'F' → Fullscreen
if, else if, and else statements to create mutually exclusive conditions. birthYear % 12, which gives you a remainder between 0 and 11.
else if copy and paste it to speed things up, just tweak the values as needed. console.log("--- Chinese Zodiac Calendar ---");
let birthYear = parseInt(prompt("Enter your birth year: "));let zodiacNumber = birthYear % 12;let zodiacAnimal; // Assign animal based on birth year
if (zodiacNumber == 0) { zodiacAnimal = "monkey";}else if (zodiacNumber == 1) { zodiacAnimal = "rooster";}else if (zodiacNumber == 2) { zodiacAnimal = "dog";}else if (zodiacNumber == 3) { zodiacAnimal = "pig";}else if (zodiacNumber == 4) { zodiacAnimal = "rat";}else if (zodiacNumber == 5) { zodiacAnimal = "ox";}else if (zodiacNumber == 6) { zodiacAnimal = "tiger";}else if (zodiacNumber == 7) { zodiacAnimal = "rabbit";}else if (zodiacNumber == 8) { zodiacAnimal = "dragon";}else if (zodiacNumber == 9) { zodiacAnimal = "snake";}else if (zodiacNumber == 10) { zodiacAnimal = "horse";}else if (zodiacNumber == 11) { zodiacAnimal = "sheep";}else { // Exit if input was invalid (NaN) console.log("Something went wrong. Exiting."); Deno.exit();}
console.log(`\nBirth year: ${birthYear} - You are the year of the...${zodiacAnimal}.\n`);
alert("Press enter to continue...");//console.log("--- Chinese Zodiac Calendar ---");
let birthYear = parseInt(prompt("Enter your birth year: "));let zodiacNumber = birthYear % 12;let zodiacAnimal; // Assign animal based on birth year
if (zodiacNumber == 0) { zodiacAnimal = "monkey";}else if (zodiacNumber == 1) { zodiacAnimal = "rooster";}else if (zodiacNumber == 2) { zodiacAnimal = "dog";}else if (zodiacNumber == 3) { zodiacAnimal = "pig";}else if (zodiacNumber == 4) { zodiacAnimal = "rat";}else if (zodiacNumber == 5) { zodiacAnimal = "ox";}else if (zodiacNumber == 6) { zodiacAnimal = "tiger";}else if (zodiacNumber == 7) { zodiacAnimal = "rabbit";}else if (zodiacNumber == 8) { zodiacAnimal = "dragon";}else if (zodiacNumber == 9) { zodiacAnimal = "snake";}else if (zodiacNumber == 10) { zodiacAnimal = "horse";}else if (zodiacNumber == 11) { zodiacAnimal = "sheep";}else { // Exit if input was invalid (NaN) console.log("Something went wrong. Exiting."); Deno.exit();}
console.log(`\nBirth year: ${birthYear} - You are the year of the...${zodiacAnimal}.\n`);
alert("Press enter to continue...");
// -----------------------------------------------------------------------------
console.log("\n--- Lottery Game ---\n");console.log("Rules: Pick two lottery numbers ranging from 0 to 9");console.log("Match two numbers and win BIG!");console.log("Match one number in order and win SMALL!\n");
let lottoNum1 = parseInt(prompt("Enter your 1st lottery number (0 to 9): "));let lottoNum2 = parseInt(prompt("Enter your 2nd lottery number (0 to 9): "));let winningNum1 = Math.floor(Math.random() * 10);let winningNum2 = Math.floor(Math.random() * 10);
// Exit the program if either lotto number is out of rangeif (lottoNum1 < 0 || lottoNum1 > 9 || lottoNum2 < 0 || lottoNum2 > 9) { console.log("Error: Your lotto numbers are invalid. Exiting"); Deno.exit();}
console.log(`The winning numbers are ${winningNum1} and ${winningNum2}!`);
if (lottoNum1 == winningNum1 && lottoNum2 == winningNum2) { console.log("You win BIG!");}else if (lottoNum1 == winningNum1 || lottoNum2 == winningNum2) { console.log("You win SMALL!");}else { console.log("You lose! Better luck next time!");}//NaN.
NaN using a function called isNaN(). Google it to see how it works.
else if statement if the lotto numbers match out of order.
Your program output should something similar to the sample output below.
--- Chinese Zodiac Calendar ---Enter your birth year: 1990
Birth year: 1990 - You are the year of the...horse.
Press enter to continue... [Enter]
--- Lottery Game ---
Rules: Pick a two lottery numbers ranging from 0 to 9Match two numbers and win BIG!Match one number in order and win SMALL!
Enter your 1st lottery number (0 to 9): 2Enter your 2nd lottery number (0 to 9): 4The winning numbers are 2 and 6!You win SMALL!You may write your reflection answers as comments at the bottom of your code.
if, else if, else change the behavior of the program compared to using multiple, separate
if statements? Describe a scenario where a separate if statement would be appropriate.
else block handles the case where the input is invalid. How does this
demonstrate the role of the else statement as a "catch-all" or "fallback" in your code?
Submit your activity and reflection answers to the appropriate dropbox.