-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
63 lines (55 loc) · 1.7 KB
/
index.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
60
61
62
63
/* write a program that uses console.log() to print all the numbers
from 1 to 200, with two eceptions. for numbers divisible by 6, print
"Shams" instead of the number, and for numbers divisible by 8 (and
not 6), print "TIIDELAB" instead. When you have that working, modify
your program to print "ShamsTIIDELAB" for numbers that are divisible
by both 6 and 8 (and still print "Shams" or "TIIDELAB" for numbers
divisible by only one of those). */
function shamsTIIDELAB() {
let i = 1;
while (i <= 200) {
if (i % 6 == 0 && i % 8 == 0) {
console.log("ShamsTIIDELAB");
} else if (i % 8 == 0) {
console.log("TIIDELAB");
} else if (i % 6 == 0) {
console.log("Shams");
} else {
console.log(i);
}
i++
}
}
shamsTIIDELAB();
function chessBoard(width) {
if (width % 2 === 0) {
str1 = " #";
str2 = "# ";
result = "";
let i = 1;
while (i <= width) {
if (i % 2 > 0) {
result += str1.repeat(width / 2) + "\n";
} else {
result += str2.repeat(width / 2) + "\n";
}
i++;
}
console.log(result);
} else {
str1 = " #";
str2 = "# ";
result = "";
let i = 1;
while (i <= width) {
if (i % 2 > 0) {
result += str1.repeat(Math.floor(width / 2)).slice(0,-1) + "\n";
} else {
result += str2.repeat(Math.floor(width / 2)).slice(0,-1) + "\n";
}
i++;
}
console.log(result);
}
}
chessBoard(8);