-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchapter_two.js
59 lines (44 loc) · 910 Bytes
/
chapter_two.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
53
54
55
56
57
58
59
//Draw a triangle of hash symbols Version 2
let hash = "#";
for (let n = 1; n <= 7; n++) {
console.log(hash.repeat(n));
}
//Draw a triangle of has symbols Version 2
for (let hash = "#"; hash.length <= 7; hash += "#") {
console.log(hash);
}
//FizzBuzz
for (let n = 1; n <= 100; n++) {
if (n % 5 == 0 && n % 3 == 0) {
console.log("FizzBuzz");
}
else if (n % 3 == 0) {
console.log("Fizz");
}
else if (n % 5 == 0) {
console.log("Buzz");
}
else console.log(n);
}
//FizzBuzz SMART WAY
for (let n = 1; n <= 100; n++) {
let result = "";
if (n % 3 == 0) result += "Fizz";
if (n % 5 == 0) result += "Buzz";
console.log(result || n);
}
// Chessboard
let chessBoard = "";
let size = 8;
for (let x = 1; x <= size; x++) {
for (y = 1; y <= size; y++) {
if ((x + y) % 2 == 0) {
chessBoard += " ";
}
else {
chessBoard += "#";
}
}
chessBoard += "\n";
}
console.log(chessBoard);