forked from code-differently/JavaScript-Loops-Lab
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathjsloops.js
More file actions
66 lines (50 loc) · 1 KB
/
jsloops.js
File metadata and controls
66 lines (50 loc) · 1 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
// 1. One to Ten
for(i = 1; i <11; i++) {
console.log(i);
}
// 2. Squares
for(i = 1; i < 11; i++) {
console.log(i*i);
}
// 3. Even Under N
for(i = 2; i < 20; i+=2){
console.log(i);
}
// 4. Sum
let count = n
let total = 0
function sum(n,m){
while(count < m){
total += n;
n++;
return total;
}
}
// 5. Are We There Yet
while (userInput = prompt("Are we there yet?")) {
if (userInput === "Yes"){
console.log("Good!")
break;
}
else {
userInput = prompt("Are we there yet?")
}
}
// 6. Triangle
for (let i = 1; i < 7; i++) {
let output = "";
for (let j = 1; j <= i; j++) {
output += j + " "
}
console.log(output.replace(/\d/g,'*'))
}
// 7. Table Square
for (let i = 1; i < 5; i++){
for (let j = 2; j < 17; j+=2){
for (let k = 3; k < 17; k+=3){
for (let l = 4; l < 17; l+=4){
console.log("| " + i, "| " + j, "| " + k, "| " + l + " |")
}
}
}
}