-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathloops.js
More file actions
76 lines (64 loc) · 1.45 KB
/
loops.js
File metadata and controls
76 lines (64 loc) · 1.45 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
/*Problem 1
for (i = 1; i <= 10; i++){
console.log(i)*/
/*Problem 2
for (let i = 1; i <=10; i++) {
console.log(i * i);
}*/
/*Problem 3
let n = 20
for (i = 1; i <= n; i++) {
if (i % 2 == 0) {
console.log(i)
}
}*/
/*Problem 5
do {
user = prompt("Are we there yet")
}while (user !== "Yes")
alert("Good!") */
//Problem 6
/*for (let i = 1; i <= 5; i++) {
let stars = ""
for (let j = 1; j <= i; j++)
stars += "*";
console.log(stars);
}*/
//Problem 7
/*rows = 4
columns = 4
for (let currentRow = 1; currentRow <= rows; currentRow++) {
let num = ""
for (let currentCol = 1; currentCol <= columns; currentCol++){
let product = ""
product += currentCol * currentRow
if (currentCol === 1){
num += `|`
}
if (product < 10 && currentCol > 1) {
num += ` ${product} |`
} else {
num += ` ${product} |`
}
}
console.log(num)
}*/
//Problem 8
rows = 6
columns = 6
for (let currentRow = 1; currentRow <= rows; currentRow++) {
let num = ""
for (let currentCol = 1; currentCol <= columns; currentCol++){
let product = ""
product += currentCol * currentRow
if (currentCol === 1){
num += `|`
}
if (product < 10 && currentCol > 1) {
num += ` ${product} |`
} else {
num += ` ${product} |`
}
}
console.log(num)
}