Skip to content

Instantly share code, notes, and snippets.

@natafaye
Last active August 6, 2021 02:45
Show Gist options
  • Save natafaye/14d00f4bb66147e0c03691cb28f7330b to your computer and use it in GitHub Desktop.
Save natafaye/14d00f4bb66147e0c03691cb28f7330b to your computer and use it in GitHub Desktop.
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")
}
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
let numToCount = prompt("What number should I count to?");
numToCount = parseInt(numToCount); // optional
for(let i = 1; i <= numToCount; i++) {
console.log(i);
}
let numToCount = prompt("What number should I count to?");
numToCount = parseInt(numToCount); // optional
for(let i = 0; i < numToCount; i++) {
console.log(i + 1);
}
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);
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")
}
}
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