forked from code-differently/JavaScript-Loops-Lab
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathscript.js
More file actions
81 lines (63 loc) · 1.81 KB
/
script.js
File metadata and controls
81 lines (63 loc) · 1.81 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
77
78
79
80
81
// I commented these all out so that they would't be called
// on at the same time, as the instructions asked for the
// same variables in some questions and several required prompts.
// 1) One to Ten
// for(let i = 1; i < 11; i++) {
// console.log(i + "\n");
// }
// 2) Squares
// for(let square = 1; square < 11; square++) {
// console.log(Math.pow(square, 2) + "\n");
// }
// 3) Even Under N
// let n = Number(prompt("Enter a number:"));
// for(let evenN = 2; evenN < n; evenN += 2) {
// console.log(evenN + "\n");
// }
// 4) Sum
// let n = Number(prompt("What is the lower number?"));
// let m = Number(prompt("What is the higher number?"));
// let total = 0;
// for(let count = n; count < m; count++) {
// total += count;
// }
// console.log(total);
// 5) Are We There Yet
// let answer = prompt("Are we there yet?");
// while(answer !== "Yes") {
// answer = prompt("Are we there yet?");
// }
// console.log("Good!");
// 6) Triangle
// I know the outer loop is redundant. But, I could't figure
// out another way to display five lines with a nested loop,
// since five is a prime number. So, I only ran the outer
// loop once.
// for(let i = 1; i <= 1; i++) {
// let level = "";
// let triangle = "";
// for(j = 1; j <= 5; j++) {
// level += "*";
// triangle += level + "\n";
// }
// console.log(triangle);
// }
// 7) Table Square
// let table = "";
// for(let y = 1; y <= 4; y++){
// for(let x = 1; x <= 4; x++){
// table += `| ${x * y} |`
// }
// table += "\n";
// }
// console.log(table);
// 8) Table Square 2
// let n = Number(prompt("How many rows/ columns?"));
// let table = "";
// for(let y = 1; y <= n; y++){
// for(let x = 1; x <= n; x++){
// table += `| ${x * y} |`
// }
// table += "\n";
// }
// console.log(table);