'F' → Fullscreen
console.log("--- Demo 1 - 99 Bottles Song ---\n");let soda = prompt("Enter your favorite soda:");let bottles = 99;
// While there are bottles left to pass around...while (bottles > 0) { console.log(`${bottles} bottles of ${soda} on the wall,`); console.log(`${bottles} bottles of ${soda}!`); console.log("You take one down, pass it around,"); bottles--; console.log(`${bottles} bottles of ${soda} on the wall!`);
// Uncomment alert() if you want to pause between iterations // alert("");}
alert("Press enter to continue...");// -----------------------------------------------------------------------------//18 collapsed lines
console.log("--- Demo 1 - 99 Bottles Song ---\n");let soda = prompt("Enter your favorite soda:");let bottles = 99;
// While there are bottles left to pass around...while (bottles > 0) { console.log(`${bottles} bottles of ${soda} on the wall,`); console.log(`${bottles} bottles of ${soda}!`); console.log("You take one down, pass it around,"); bottles--; console.log(`${bottles} bottles of ${soda} on the wall!`);
// Uncomment alert() if you want to pause between iterations // alert("");}
alert("Press enter to continue...");// -----------------------------------------------------------------------------
console.log("--- Demo 2 - Turn-Based Battle ---\n");
let playerHealth = 10;let enemyHealth = 6;let fighting = true;
// Another suitable condition: playerHealth > 0 && enemyHealth == 0while (fighting) { console.log("Health: " + playerHealth); console.log("Goblin: " + enemyHealth); console.log("\n-Menu-"); console.log("1) Attack"); console.log("2) Heal"); let choice = prompt("->").toLowerCase();
if (choice == "1" || choice == "attack") { console.log("Player attacks!"); let playerAttack = Math.floor(Math.random() * 6); // 0 to 5
if (playerAttack > 0) { console.log(`You did ${playerAttack} damage.`); enemyHealth = enemyHealth - playerAttack; } else { console.log("Missed!"); } } else if (choice == "2" || choice == "heal") { let potion = Math.floor(Math.random() * 3) + 1; // 1 to 3 console.log(`Healed ${potion} points.`); playerHealth = playerHealth + potion; } else { console.log("Invalid option. You lose your turn!"); }
if (enemyHealth > 0) { console.log("Goblin attacks!"); let enemyAttack = Math.floor(Math.random() * 4); // 0 to 3
if (enemyAttack > 0) { console.log(`Goblin did ${enemyAttack} damage.`); playerHealth = playerHealth - enemyAttack; } else { console.log("Missed!"); } } else { console.log("Goblin defeated!"); fighting = false; // Exit battle }
if (playerHealth <= 0) { console.log("You were defeated!"); fighting = false; // Exit battle }}//Your program output should something similar to the sample output below.
--- Demo 1 - 99 Bottles Song ---
Enter your favorite soda: Code Zero99 bottles of Code Zero on the wall,99 bottles of Code Zero!You take one down, pass it around,98 bottles of Code Zero on the wall!Press enter to continue... [Enter]--- Demo 2 - Turn-Based Battle ---
Health: 10Goblin: 6
-Menu-1) Attack2) Heal-> 1Player attacks!You did 3 damage.Goblin attacks!Missed!Health: 10Goblin: 3
-Menu-1) Attack2) Heal-> 1Player attacks!You did 4 damage.Goblin defeated!You may write your reflection answers as comments at the bottom of your code.
Submit your activity and reflection answers to the appropriate dropbox.