Created
January 12, 2022 02:44
-
-
Save natafaye/b02f95f1d149f21d4fde9a1d1343fdac to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Prompt for a number of cats and parse it into a number | |
var numCats = prompt("How many cats do you have?") | |
numCats = parseInt(numCats) | |
// Loop as long as they don't give us a real number | |
while( !(numCats >= 0) ) { | |
numCats = prompt("No really, how many cats?"); | |
numCats = parseInt(numCats) | |
} | |
// Shame them if they don't have a good number of cats | |
if(numCats === 0) { | |
alert("That's sad"); | |
} | |
else if(numCats < 2) { | |
alert("That's too few cats") | |
} | |
else if(numCats > 6) { | |
alert("That's too many cats") | |
} | |
else { | |
alert("Good job. You're making good choices.") | |
} | |
// Keep giving them cats until they have 3 | |
while(numCats < 3) { | |
numCats++; | |
alert("Here's a cat! You now have " + numCats + " cats"); | |
} | |
// Give them a set number of cats | |
var numCatsWeOwn = 7; | |
for(var i = 0; i < numCatsWeOwn; i++) { // this will run with i = 0, 1, 2, 3, 4, 5, and 6 | |
numCats++; | |
alert("Here's a cat! You now have " + numCats + " cats"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment