Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions jsloops.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,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;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would work perfectly if return was outside of loop (-1)

}
}

// 5. Are We There Yet

while (userInput = prompt("Are we there yet?")) {
if (userInput === "Yes"){
console.log("Good!")
break;
}
else {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would work if the second prompt was not there (-2)

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
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4x4 grid (code-differently#7) is working but not the nxn grid (code-differently#8) (-10)


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 + " |")
}
}
}
}