Skip to content

Instantly share code, notes, and snippets.

@natafaye
Last active June 30, 2021 00:43
Show Gist options
  • Select an option

  • Save natafaye/fcd6201065a687afea86a86bd11f87f0 to your computer and use it in GitHub Desktop.

Select an option

Save natafaye/fcd6201065a687afea86a86bd11f87f0 to your computer and use it in GitHub Desktop.
// Bitter Magic 8-Ball
let question = prompt("What's your question?");
let firstName = prompt("What's your name?");
if(question === null) {
if(firstName === "Bob") {
alert("Have a great day!");
}
else {
alert("Fine then.");
}
}
else if(!question.includes("?")) {
alert("Is that even a question?");
}
else if(question.startsWith("Should I")) {
alert("Don't do it.");
}
else if(question.includes("love")) {
alert("THEY DON'T LOVE YOU");
}
else {
alert("Maybe");
}
// Number Guessing Game
let answer = 7;
let guess;
do {
guess = prompt("What number am I thinking of?");
if(guess === null) {
break;
}
//guess = parseInt(guess);
} while(parseInt(guess) !== answer)
if(guess === answer) {
alert('You win!')
}
// Counting Practice
let howHigh = parseInt(prompt("How high should I count?"));
// let howHigh = prompt("How high should I count?");
// howHigh = parseInt(howHigh);
while(isNaN(howHigh)) {
if(howHigh === null) {
alert("Goodbye!")
break;
}
howHigh = parseInt(prompt("That's not a number. How high should I count?"));
}
if(howHigh !== null) {
for(let i = 0; i < howHigh; i++) {
alert(i + 1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment