-
Notifications
You must be signed in to change notification settings - Fork 0
/
chapter02-ex.js
52 lines (44 loc) · 924 Bytes
/
chapter02-ex.js
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
// Looping a Triangle
for (var i = 1; i < 7; i++) {
let str = "";
for (var n = 1; n <= i; n++) {
str += "#";
}
console.log(str);
}
// FizzBuzz
function fizzBuzzPrinter(start=1, end=100) {
for (var i = start; i <= end; i++) {
if ( (i % 3 === 0) && (i % 5 === 0)) {
console.log("FizzBuzz");
} else if (i % 3 === 0) {
console.log('Fizz');
} else if (i % 5 === 0) {
console.log('Buzz');
} else {
console.log(i);
}
}
}
// ChessBoard
function fenceGrid(size=8) {
for (var i = 1; i <= size; i++) {
let line = (i % 2 === 1) ? " " : "#";
for (var n = 2; n <= size; n++ ) {
if (i % 2 === 1) {
if (n % 2 === 1) {
line += " ";
} else {
line += "#";
}
} else {
if (n % 2 === 1) {
line += "#";
} else {
line += " ";
}
}
}
console.log(line);
}
}