-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchapter_2-Program_Structure.js
More file actions
60 lines (51 loc) · 909 Bytes
/
Copy pathchapter_2-Program_Structure.js
File metadata and controls
60 lines (51 loc) · 909 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/* Write program to print out:
#
##
###
####
#####
######
#######
*/
var string = ""
for (var i = 0; i < 7; i++) {
string += "#"
console.log(string)
}
console.log()
/* Write program to print number from 1 to 100
"Fizz" if number divisible by 3
"Buzz" if number divisible by 5
"FizzBuzz" if number divisible by 3 and 5
*/
for (var i = 1; i <= 100; i++) {
if (i % 3 == 0 && i % 5 == 0) {
process.stdout.write("FizzBuzz ")
} else if (i % 3 == 0) {
process.stdout.write("Fizz ")
} else if (i % 5 == 0) {
process.stdout.write("Buzz ")
} else {
process.stdout.write(i + " ")
}
}
console.log()
/* Print chessboard
# # # #
# # # #
# # # #
# # # #
# # # #
# # # #
# # # #
# # # #
*/
var size = 16, odd = "", even = ""
for (var i = 0; i < size / 2; i++) {
odd += " #"
even += "# "
}
for (var i = 0; i < size / 2; i++) {
console.log(odd)
console.log(even)
}