Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save LukeSkyRunner/21cc83e32cbdf8cda1f35d83f5743738 to your computer and use it in GitHub Desktop.
Save LukeSkyRunner/21cc83e32cbdf8cda1f35d83f5743738 to your computer and use it in GitHub Desktop.
Javascript Loops & Iteration Practice
//In the CodePen above, make the loop start at 30, and count down to 0
let counter = 30;
while (counter >= 0){
console.log(counter);
counter -= 1;
}
//Using a for loop, display a countdown from 10 to 0. You will need to write i-- in your for aloop
for (let i=10; i=0; i--){
console.log (i)
}
console.log ("Boom!")
//print the numbers 1 through 50
//if the number is divisible by 5, skip it,
//if the number is divisible by 10 or 15, print “Donkey!”,
//if the number is not divisible by 2 and the previous number is divisible by 10, print“Monkey!”
for (let i=0; i<=50; i++){
if (i % 5 === 0){
continue;
}
else if (i % 10 === 0 || i % 15 === 0){
console.log ("Donkey!");
}
else if (i % 2 !== 0 && i-1 % 10 ===0){
console.log ("Monkey!");
}
else {
console.log (i);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment