Please follow the instructions below.
- Create an HTML file named
break_continue_js.html
within the~/vagrant-lamp/sites/codeup.dev/public
folder on your Mac. - Use
Math.floor((Math.random()*50)+1)
to generate a random number between 1 and 50. If the number is not odd, keep getting a new random number till it is odd. - Use console.log to log all the odd numbers from 1 to 50, except the random odd number you generated, by using
break
andcontinue
. Try to match the output shown below (your random number will be different). - Finally, save your work, commit the changes to your git repository, and push to GitHub.
Your output should look like this (but a different random odd number to skip):
Random odd number to skip is: 27
Here is an odd number: 1
Here is an odd number: 3
Here is an odd number: 5
Here is an odd number: 7
Here is an odd number: 9
Here is an odd number: 11
Here is an odd number: 13
Here is an odd number: 15
Here is an odd number: 17
Here is an odd number: 19
Here is an odd number: 21
Here is an odd number: 23
Here is an odd number: 25
Yikes! Skipping number: 27
Here is an odd number: 29
Here is an odd number: 31
Here is an odd number: 33
Here is an odd number: 35
Here is an odd number: 37
Here is an odd number: 39
Here is an odd number: 41
Here is an odd number: 43
Here is an odd number: 45
Here is an odd number: 47
Here is an odd number: 49
###solution:
"use strict"
var randoskip=0;
while(randoskip%2==0){
randoskip = Math.floor((Math.random()*50)+1);
}
for (var i = 1; i <= 50; i++) {
if (i == randoskip) {
console.log("Yikes! skipping number: "+i);
continue;
}
if (i%2 != 0) {
console.log("Here is an odd number: "+i);
}
};