Last active
August 6, 2021 02:45
-
-
Save natafaye/14d00f4bb66147e0c03691cb28f7330b 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
let numCats = prompt("How many cats do you have?"); | |
numCats = parseInt(numCats); // convert the string (ex: "3") to the number (ex: 3) | |
if(numCats < 1) { | |
console.log("You need more cats") | |
} | |
else if(numCats > 10) { | |
console.log("That is tooo many cats") | |
} | |
else { | |
console.log("You make good choices") | |
} |
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
let numCats = prompt("How many cats do you have?"); | |
numCats = parseInt(numCats); // convert the string (ex: "3") to the number (ex: 3) | |
while(numCats < 5) { | |
numCats++; // Give them a cat | |
} | |
console.log(numCats); // This will log out 5 |
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
let numToCount = prompt("What number should I count to?"); | |
numToCount = parseInt(numToCount); // optional | |
for(let i = 1; i <= numToCount; i++) { | |
console.log(i); | |
} |
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
let numToCount = prompt("What number should I count to?"); | |
numToCount = parseInt(numToCount); // optional | |
for(let i = 0; i < numToCount; i++) { | |
console.log(i + 1); | |
} |
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
let numToCount = prompt("What number should I count to?"); | |
numToCount = parseInt(numToCount); // optional | |
let countMessage = ""; | |
for(let i = 1; i <= numToCount; i++) { | |
countMessage += i + " "; | |
} | |
console.log(countMessage); |
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
let numToCount = prompt("What number should I count to?"); | |
numToCount = parseInt(numToCount); // optional | |
for(let i = 1; i <= numToCount; i++) { | |
if(i % 2 === 1) { | |
console.log(i + " odd") | |
} | |
else { | |
console.log(i + " even") | |
} | |
} |
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
let numToCount = prompt("What number should I count to?"); | |
numToCount = parseInt(numToCount); // optional | |
let isOdd = true; | |
for(let i = 1; i <= numToCount; i++) { | |
if(isOdd) { | |
console.log(i + " odd") | |
} | |
else { | |
console.log(i + " even") | |
} | |
isOdd = !isOdd; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment