Skip to content

Commit 2f9bce4

Browse files
committed
add solutions of chapter 2
0 parents  commit 2f9bce4

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
eloquentJS_mySolutions.js

chapter_two.js

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
//Draw a triangle of hash symbols Version 2
2+
3+
let hash = "#";
4+
for (let n = 1; n <= 7; n++) {
5+
console.log(hash.repeat(n));
6+
}
7+
8+
//Draw a triangle of has symbols Version 2
9+
10+
for (let hash = "#"; hash.length <= 7; hash += "#") {
11+
console.log(hash);
12+
}
13+
14+
//FizzBuzz
15+
16+
for (let n = 1; n <= 100; n++) {
17+
if (n % 5 == 0 && n % 3 == 0) {
18+
console.log("FizzBuzz");
19+
}
20+
else if (n % 3 == 0) {
21+
console.log("Fizz");
22+
}
23+
else if (n % 5 == 0) {
24+
console.log("Buzz");
25+
}
26+
else console.log(n);
27+
}
28+
29+
//FizzBuzz SMART WAY
30+
31+
for (let n = 1; n <= 100; n++) {
32+
let result = "";
33+
if (n % 3 == 0) result += "Fizz";
34+
if (n % 5 == 0) result += "Buzz";
35+
console.log(result || n);
36+
}
37+
38+
// Chessboard
39+
40+
let chessBoard = "";
41+
let size = 8;
42+
43+
for (let x = 1; x <= size; x++) {
44+
45+
for (y = 1; y <= size; y++) {
46+
47+
if ((x + y) % 2 == 0) {
48+
chessBoard += " ";
49+
}
50+
51+
else {
52+
chessBoard += "#";
53+
}
54+
}
55+
56+
chessBoard += "\n";
57+
}
58+
59+
console.log(chessBoard);

0 commit comments

Comments
 (0)