-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathLoops.js
More file actions
65 lines (56 loc) · 1.27 KB
/
Loops.js
File metadata and controls
65 lines (56 loc) · 1.27 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
// 1. Display the numbers 1 to 10 in the console.
for ( let i = 1; i <= 10; i++) {
console.log(i);
}
// 2. Display the square numbers up to 100 in the console.
for ( let i = 1; i <= 10; i++) {
let y = Math.pow(i, 2);
console.log(y);
}
// 3. Display the positive even number less then n in the console.
for (let i = 1; i < 20; i++) {
if (i % 2 === 0)
console.log(i);
}
// 4. Calculate the sum of the number from n to, but not including m, and returns the answer.
let sum = 0;
for (let i =5; i < 10; i++) {
sum += i;
}
console.log(sum);
// 5. Are We There Yet.
do {
question = prompt("Are we there yet?");
} while (question != "Yes")
console.log("Good!");
// 6. Triangle
let stars = '';
for (i = 1; i <= 6; i++) {
for (s = 1; s < i; s++){
stars = stars + ("*");
}
console.log(stars)
stars = '';
}
// 7. Table Square
let result = '';
for (i = 1; i <=4; i++) {
for (a = 1; a <= 4; a++) {
for (b = " | "; b <= 4; b++) {
}
result += (i * a + b)
}
result += "\n"
}
console.log(result);
//8. Table Square 2
let square2 = '';
for (i = 1; i <= 6; i++) {
for (a = 1; a <= 6; a++) {
for (b = " | "; b <= 6; b++) {
}
square2 += (i * a +b);
}
square2 += "\n"
}
console.log(square2);