From b99d78858be1d1ab1aae3417e00c38a458a72ae3 Mon Sep 17 00:00:00 2001 From: Kris Koishigawa Date: Wed, 29 Jan 2020 15:13:18 +0900 Subject: [PATCH] fix: basic js rpg spacing and tests Replaced tabs with spaces so spacing is consistent in the monaco editor. Also adjust some tests to account for the new loop protection. --- .../basic-javascript-rpg-game/part-100.md | 362 +++++------ .../basic-javascript-rpg-game/part-101.md | 372 ++++++------ .../basic-javascript-rpg-game/part-102.md | 382 ++++++------ .../basic-javascript-rpg-game/part-103.md | 386 ++++++------ .../basic-javascript-rpg-game/part-104.md | 386 ++++++------ .../basic-javascript-rpg-game/part-105.md | 388 ++++++------ .../basic-javascript-rpg-game/part-106.md | 390 ++++++------ .../basic-javascript-rpg-game/part-107.md | 394 ++++++------ .../basic-javascript-rpg-game/part-108.md | 402 ++++++------- .../basic-javascript-rpg-game/part-109.md | 412 ++++++------- .../basic-javascript-rpg-game/part-110.md | 422 ++++++------- .../basic-javascript-rpg-game/part-111.md | 432 ++++++------- .../basic-javascript-rpg-game/part-112.md | 442 +++++++------- .../basic-javascript-rpg-game/part-113.md | 440 +++++++------- .../basic-javascript-rpg-game/part-114.md | 458 +++++++------- .../basic-javascript-rpg-game/part-115.md | 484 +++++++-------- .../basic-javascript-rpg-game/part-116.md | 486 +++++++-------- .../basic-javascript-rpg-game/part-117.md | 472 +++++++-------- .../basic-javascript-rpg-game/part-118.md | 470 +++++++-------- .../basic-javascript-rpg-game/part-119.md | 468 +++++++-------- .../basic-javascript-rpg-game/part-120.md | 468 +++++++-------- .../basic-javascript-rpg-game/part-121.md | 468 +++++++-------- .../basic-javascript-rpg-game/part-122.md | 468 +++++++-------- .../basic-javascript-rpg-game/part-123.md | 472 +++++++-------- .../basic-javascript-rpg-game/part-124.md | 468 +++++++-------- .../basic-javascript-rpg-game/part-125.md | 468 +++++++-------- .../basic-javascript-rpg-game/part-126.md | 466 +++++++------- .../basic-javascript-rpg-game/part-127.md | 474 +++++++-------- .../basic-javascript-rpg-game/part-128.md | 492 +++++++-------- .../basic-javascript-rpg-game/part-129.md | 492 +++++++-------- .../basic-javascript-rpg-game/part-130.md | 490 +++++++-------- .../basic-javascript-rpg-game/part-131.md | 486 +++++++-------- .../basic-javascript-rpg-game/part-132.md | 488 +++++++-------- .../basic-javascript-rpg-game/part-133.md | 490 +++++++-------- .../basic-javascript-rpg-game/part-134.md | 490 +++++++-------- .../basic-javascript-rpg-game/part-135.md | 502 ++++++++-------- .../basic-javascript-rpg-game/part-136.md | 512 ++++++++-------- .../basic-javascript-rpg-game/part-137.md | 512 ++++++++-------- .../basic-javascript-rpg-game/part-138.md | 512 ++++++++-------- .../basic-javascript-rpg-game/part-139.md | 520 ++++++++-------- .../basic-javascript-rpg-game/part-140.md | 526 ++++++++-------- .../basic-javascript-rpg-game/part-141.md | 528 ++++++++-------- .../basic-javascript-rpg-game/part-142.md | 532 ++++++++-------- .../basic-javascript-rpg-game/part-143.md | 532 ++++++++-------- .../basic-javascript-rpg-game/part-144.md | 530 ++++++++-------- .../basic-javascript-rpg-game/part-145.md | 530 ++++++++-------- .../basic-javascript-rpg-game/part-146.md | 530 ++++++++-------- .../basic-javascript-rpg-game/part-147.md | 530 ++++++++-------- .../basic-javascript-rpg-game/part-148.md | 528 ++++++++-------- .../basic-javascript-rpg-game/part-149.md | 538 ++++++++--------- .../basic-javascript-rpg-game/part-150.md | 556 ++++++++--------- .../basic-javascript-rpg-game/part-151.md | 566 ++++++++--------- .../basic-javascript-rpg-game/part-152.md | 568 +++++++++--------- .../basic-javascript-rpg-game/part-153.md | 568 +++++++++--------- .../basic-javascript-rpg-game/part-17.md | 2 +- .../basic-javascript-rpg-game/part-18.md | 2 +- .../basic-javascript-rpg-game/part-19.md | 2 +- .../basic-javascript-rpg-game/part-20.md | 4 +- .../basic-javascript-rpg-game/part-21.md | 4 +- .../basic-javascript-rpg-game/part-22.md | 6 +- .../basic-javascript-rpg-game/part-23.md | 4 +- .../basic-javascript-rpg-game/part-24.md | 4 +- .../basic-javascript-rpg-game/part-25.md | 4 +- .../basic-javascript-rpg-game/part-26.md | 18 +- .../basic-javascript-rpg-game/part-27.md | 20 +- .../basic-javascript-rpg-game/part-28.md | 22 +- .../basic-javascript-rpg-game/part-29.md | 22 +- .../basic-javascript-rpg-game/part-30.md | 34 +- .../basic-javascript-rpg-game/part-31.md | 44 +- .../basic-javascript-rpg-game/part-32.md | 38 +- .../basic-javascript-rpg-game/part-33.md | 40 +- .../basic-javascript-rpg-game/part-34.md | 44 +- .../basic-javascript-rpg-game/part-35.md | 58 +- .../basic-javascript-rpg-game/part-36.md | 70 +-- .../basic-javascript-rpg-game/part-37.md | 84 +-- .../basic-javascript-rpg-game/part-38.md | 84 +-- .../basic-javascript-rpg-game/part-39.md | 84 +-- .../basic-javascript-rpg-game/part-40.md | 84 +-- .../basic-javascript-rpg-game/part-41.md | 84 +-- .../basic-javascript-rpg-game/part-42.md | 84 +-- .../basic-javascript-rpg-game/part-43.md | 84 +-- .../basic-javascript-rpg-game/part-44.md | 84 +-- .../basic-javascript-rpg-game/part-45.md | 84 +-- .../basic-javascript-rpg-game/part-46.md | 94 +-- .../basic-javascript-rpg-game/part-47.md | 106 ++-- .../basic-javascript-rpg-game/part-48.md | 106 ++-- .../basic-javascript-rpg-game/part-49.md | 106 ++-- .../basic-javascript-rpg-game/part-50.md | 106 ++-- .../basic-javascript-rpg-game/part-51.md | 106 ++-- .../basic-javascript-rpg-game/part-52.md | 114 ++-- .../basic-javascript-rpg-game/part-53.md | 120 ++-- .../basic-javascript-rpg-game/part-54.md | 108 ++-- .../basic-javascript-rpg-game/part-55.md | 108 ++-- .../basic-javascript-rpg-game/part-56.md | 106 ++-- .../basic-javascript-rpg-game/part-57.md | 106 ++-- .../basic-javascript-rpg-game/part-58.md | 138 ++--- .../basic-javascript-rpg-game/part-59.md | 170 +++--- .../basic-javascript-rpg-game/part-60.md | 170 +++--- .../basic-javascript-rpg-game/part-61.md | 170 +++--- .../basic-javascript-rpg-game/part-62.md | 170 +++--- .../basic-javascript-rpg-game/part-63.md | 182 +++--- .../basic-javascript-rpg-game/part-64.md | 192 +++--- .../basic-javascript-rpg-game/part-65.md | 190 +++--- .../basic-javascript-rpg-game/part-66.md | 190 +++--- .../basic-javascript-rpg-game/part-67.md | 190 +++--- .../basic-javascript-rpg-game/part-68.md | 188 +++--- .../basic-javascript-rpg-game/part-69.md | 186 +++--- .../basic-javascript-rpg-game/part-70.md | 186 +++--- .../basic-javascript-rpg-game/part-71.md | 182 +++--- .../basic-javascript-rpg-game/part-72.md | 178 +++--- .../basic-javascript-rpg-game/part-73.md | 170 +++--- .../basic-javascript-rpg-game/part-74.md | 170 +++--- .../basic-javascript-rpg-game/part-75.md | 170 +++--- .../basic-javascript-rpg-game/part-76.md | 204 +++---- .../basic-javascript-rpg-game/part-77.md | 238 ++++---- .../basic-javascript-rpg-game/part-78.md | 238 ++++---- .../basic-javascript-rpg-game/part-79.md | 242 ++++---- .../basic-javascript-rpg-game/part-80.md | 238 ++++---- .../basic-javascript-rpg-game/part-81.md | 238 ++++---- .../basic-javascript-rpg-game/part-82.md | 238 ++++---- .../basic-javascript-rpg-game/part-83.md | 240 ++++---- .../basic-javascript-rpg-game/part-84.md | 258 ++++---- .../basic-javascript-rpg-game/part-85.md | 274 ++++----- .../basic-javascript-rpg-game/part-86.md | 274 ++++----- .../basic-javascript-rpg-game/part-87.md | 278 ++++----- .../basic-javascript-rpg-game/part-88.md | 288 ++++----- .../basic-javascript-rpg-game/part-89.md | 310 +++++----- .../basic-javascript-rpg-game/part-90.md | 322 +++++----- .../basic-javascript-rpg-game/part-91.md | 322 +++++----- .../basic-javascript-rpg-game/part-92.md | 322 +++++----- .../basic-javascript-rpg-game/part-93.md | 328 +++++----- .../basic-javascript-rpg-game/part-94.md | 338 +++++------ .../basic-javascript-rpg-game/part-95.md | 344 +++++------ .../basic-javascript-rpg-game/part-96.md | 348 +++++------ .../basic-javascript-rpg-game/part-97.md | 352 +++++------ .../basic-javascript-rpg-game/part-98.md | 356 +++++------ .../basic-javascript-rpg-game/part-99.md | 358 +++++------ 137 files changed, 19186 insertions(+), 19186 deletions(-) diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-100.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-100.md index 299b8fd1f7..45c5b016fb 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-100.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-100.md @@ -56,22 +56,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -93,30 +93,30 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + } ]; // initialize buttons @@ -124,14 +124,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -158,65 +158,65 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= monsters[fighting].level; - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= monsters[fighting].level; + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; } function dodge() { @@ -337,22 +337,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -374,30 +374,30 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + } ]; // initialize buttons @@ -405,14 +405,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -424,7 +424,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -439,67 +439,67 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= monsters[fighting].level; - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= monsters[fighting].level; + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; } function dodge() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-101.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-101.md index 89372f9668..8024887c62 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-101.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-101.md @@ -56,22 +56,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -93,30 +93,30 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + } ]; // initialize buttons @@ -124,14 +124,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -158,67 +158,67 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= monsters[fighting].level; - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= monsters[fighting].level; + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; } function dodge() { @@ -339,22 +339,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -376,30 +376,30 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + } ]; // initialize buttons @@ -407,14 +407,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -426,7 +426,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -441,70 +441,70 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= monsters[fighting].level; - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= monsters[fighting].level; + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } } function dodge() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-102.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-102.md index b210342fd8..410151eec7 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-102.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-102.md @@ -68,22 +68,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -105,30 +105,30 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + } ]; // initialize buttons @@ -136,14 +136,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -170,70 +170,70 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= monsters[fighting].level; - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= monsters[fighting].level; + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } } function dodge() { @@ -354,22 +354,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -391,30 +391,30 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + } ]; // initialize buttons @@ -422,14 +422,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -441,7 +441,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -456,72 +456,72 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= monsters[fighting].level; - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - defeatMonster(); - } + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= monsters[fighting].level; + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + defeatMonster(); + } } function dodge() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-103.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-103.md index d68c01c25c..a7e86b573e 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-103.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-103.md @@ -56,22 +56,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -93,30 +93,30 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + } ]; // initialize buttons @@ -124,14 +124,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -158,72 +158,72 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= monsters[fighting].level; - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - defeatMonster(); - } + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= monsters[fighting].level; + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + defeatMonster(); + } } function dodge() { @@ -344,22 +344,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -381,30 +381,30 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + } ]; // initialize buttons @@ -412,14 +412,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -431,7 +431,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -446,72 +446,72 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= monsters[fighting].level; - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - defeatMonster(); - } + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= monsters[fighting].level; + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + defeatMonster(); + } } function dodge() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-104.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-104.md index ce79c3c5b1..143e03ac80 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-104.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-104.md @@ -56,22 +56,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -93,30 +93,30 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + } ]; // initialize buttons @@ -124,14 +124,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -158,72 +158,72 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= monsters[fighting].level; - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - defeatMonster(); - } + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= monsters[fighting].level; + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + defeatMonster(); + } } function dodge() { @@ -350,22 +350,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -387,30 +387,30 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + } ]; // initialize buttons @@ -418,14 +418,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -437,7 +437,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -452,72 +452,72 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= monsters[fighting].level; - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - defeatMonster(); - } + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= monsters[fighting].level; + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + defeatMonster(); + } } function dodge() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-105.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-105.md index 1eae1719a3..d90e71f021 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-105.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-105.md @@ -58,22 +58,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -95,30 +95,30 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + } ]; // initialize buttons @@ -126,14 +126,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -160,72 +160,72 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= monsters[fighting].level; - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - defeatMonster(); - } + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= monsters[fighting].level; + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + defeatMonster(); + } } function dodge() { @@ -353,22 +353,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -390,30 +390,30 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + } ]; // initialize buttons @@ -421,14 +421,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -440,7 +440,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -455,72 +455,72 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= monsters[fighting].level; - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - defeatMonster(); - } + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= monsters[fighting].level; + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + defeatMonster(); + } } function dodge() { @@ -528,7 +528,7 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); + gold += Math.floor(monsters[fighting].level * 6.7); } function lose() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-106.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-106.md index 49933cc83d..57d2374f9f 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-106.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-106.md @@ -56,22 +56,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -93,30 +93,30 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + } ]; // initialize buttons @@ -124,14 +124,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -158,72 +158,72 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= monsters[fighting].level; - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - defeatMonster(); - } + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= monsters[fighting].level; + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + defeatMonster(); + } } function dodge() { @@ -231,7 +231,7 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); + gold += Math.floor(monsters[fighting].level * 6.7); } function lose() { @@ -352,22 +352,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -389,30 +389,30 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + } ]; // initialize buttons @@ -420,14 +420,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -439,7 +439,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -454,72 +454,72 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= monsters[fighting].level; - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - defeatMonster(); - } + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= monsters[fighting].level; + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + defeatMonster(); + } } function dodge() { @@ -527,7 +527,7 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); + gold += Math.floor(monsters[fighting].level * 6.7); xp += monsters[fighting].level; } diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-107.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-107.md index 75a5409fc4..549925dc33 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-107.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-107.md @@ -56,22 +56,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -93,30 +93,30 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + } ]; // initialize buttons @@ -124,14 +124,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -158,72 +158,72 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= monsters[fighting].level; - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - defeatMonster(); - } + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= monsters[fighting].level; + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + defeatMonster(); + } } function dodge() { @@ -353,22 +353,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -390,30 +390,30 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + } ]; // initialize buttons @@ -421,14 +421,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -440,7 +440,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -455,72 +455,72 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= monsters[fighting].level; - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - defeatMonster(); - } + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= monsters[fighting].level; + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + defeatMonster(); + } } function dodge() { @@ -528,10 +528,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; } function lose() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-108.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-108.md index 82ede305f7..1df8e99799 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-108.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-108.md @@ -56,22 +56,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -93,30 +93,30 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + } ]; // initialize buttons @@ -124,14 +124,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -158,72 +158,72 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= monsters[fighting].level; - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - defeatMonster(); - } + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= monsters[fighting].level; + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + defeatMonster(); + } } function dodge() { @@ -231,10 +231,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; } @@ -356,22 +356,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -393,30 +393,30 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + } ]; // initialize buttons @@ -424,14 +424,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -443,7 +443,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -458,72 +458,72 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= monsters[fighting].level; - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - defeatMonster(); - } + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= monsters[fighting].level; + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + defeatMonster(); + } } function dodge() { @@ -531,10 +531,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-109.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-109.md index fa2674c01b..0b5b2701ae 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-109.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-109.md @@ -57,22 +57,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -94,30 +94,30 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + } ]; // initialize buttons @@ -125,14 +125,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -159,72 +159,72 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= monsters[fighting].level; - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - defeatMonster(); - } + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= monsters[fighting].level; + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + defeatMonster(); + } } function dodge() { @@ -232,10 +232,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -357,22 +357,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -394,36 +394,36 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: "The monster screams Arg! as it dies. You gain experience points and find gold." - } + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: "The monster screams Arg! as it dies. You gain experience points and find gold." + } ]; // initialize buttons @@ -431,14 +431,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -450,7 +450,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -465,72 +465,72 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= monsters[fighting].level; - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - defeatMonster(); - } + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= monsters[fighting].level; + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + defeatMonster(); + } } function dodge() { @@ -538,10 +538,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-110.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-110.md index ba488707c3..b411ba32e8 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-110.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-110.md @@ -57,22 +57,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -94,36 +94,36 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: "The monster screams Arg! as it dies. You gain experience points and find gold." - } + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: "The monster screams Arg! as it dies. You gain experience points and find gold." + } ]; // initialize buttons @@ -131,14 +131,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -165,72 +165,72 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= monsters[fighting].level; - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - defeatMonster(); - } + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= monsters[fighting].level; + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + defeatMonster(); + } } function dodge() { @@ -238,10 +238,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -363,22 +363,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -400,36 +400,36 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - } + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + } ]; // initialize buttons @@ -437,14 +437,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -456,7 +456,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -471,72 +471,72 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= monsters[fighting].level; - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - defeatMonster(); - } + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= monsters[fighting].level; + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + defeatMonster(); + } } function dodge() { @@ -544,10 +544,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-111.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-111.md index a35bfc0e2b..f6eef5c688 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-111.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-111.md @@ -57,22 +57,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -94,36 +94,36 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - } + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + } ]; // initialize buttons @@ -131,14 +131,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -165,72 +165,72 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= monsters[fighting].level; - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - defeatMonster(); - } + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= monsters[fighting].level; + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + defeatMonster(); + } } function dodge() { @@ -238,10 +238,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -366,22 +366,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -403,42 +403,42 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" - } + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" + } ]; // initialize buttons @@ -446,14 +446,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -465,7 +465,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -480,72 +480,72 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= monsters[fighting].level; - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - defeatMonster(); - } + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= monsters[fighting].level; + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + defeatMonster(); + } } function dodge() { @@ -553,10 +553,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-112.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-112.md index 764211becd..0425ae02b4 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-112.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-112.md @@ -56,22 +56,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -93,42 +93,42 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" - } + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" + } ]; // initialize buttons @@ -136,14 +136,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -170,72 +170,72 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= monsters[fighting].level; - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - defeatMonster(); - } + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= monsters[fighting].level; + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + defeatMonster(); + } } function dodge() { @@ -243,10 +243,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -371,22 +371,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -408,42 +408,42 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" - } + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" + } ]; // initialize buttons @@ -451,15 +451,15 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -471,7 +471,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -486,72 +486,72 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= monsters[fighting].level; - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - defeatMonster(); - } + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= monsters[fighting].level; + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + defeatMonster(); + } } function dodge() { @@ -559,10 +559,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-113.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-113.md index f47a29c3f8..8e39ea4fce 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-113.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-113.md @@ -56,22 +56,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -93,42 +93,42 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" - } + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" + } ]; // initialize buttons @@ -138,13 +138,13 @@ button3.onclick = fightDragon; function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -171,72 +171,72 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= monsters[fighting].level; - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - defeatMonster(); - } + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= monsters[fighting].level; + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + defeatMonster(); + } } function dodge() { @@ -244,10 +244,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -372,22 +372,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -409,42 +409,42 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" - } + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" + } ]; // initialize buttons @@ -452,15 +452,15 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -472,7 +472,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -487,72 +487,72 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= monsters[fighting].level; - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - defeatMonster(); - } + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= monsters[fighting].level; + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + defeatMonster(); + } } function dodge() { @@ -560,10 +560,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-114.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-114.md index 3cc5f27cc4..a5b153e375 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-114.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-114.md @@ -58,22 +58,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -95,42 +95,42 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" - } + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" + } ]; // initialize buttons @@ -140,13 +140,13 @@ button3.onclick = fightDragon; function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -173,72 +173,72 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= monsters[fighting].level; - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - defeatMonster(); - } + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= monsters[fighting].level; + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + defeatMonster(); + } } function dodge() { @@ -246,10 +246,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -372,22 +372,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -409,42 +409,42 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" - } + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" + } ]; // initialize buttons @@ -452,15 +452,15 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -472,7 +472,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -487,72 +487,72 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= monsters[fighting].level; - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - defeatMonster(); - } + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= monsters[fighting].level; + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + defeatMonster(); + } } function dodge() { @@ -560,10 +560,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -572,15 +572,15 @@ function lose() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } ``` diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-115.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-115.md index 3e9fba9bd4..15939240f8 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-115.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-115.md @@ -56,22 +56,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -93,42 +93,42 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" - } + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" + } ]; // initialize buttons @@ -138,13 +138,13 @@ button3.onclick = fightDragon; function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -171,72 +171,72 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= monsters[fighting].level; - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - defeatMonster(); - } + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= monsters[fighting].level; + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + defeatMonster(); + } } function dodge() { @@ -244,10 +244,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -256,15 +256,15 @@ function lose() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } @@ -382,22 +382,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -419,42 +419,42 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" - } + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" + } ]; // initialize buttons @@ -462,15 +462,15 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -482,7 +482,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -497,76 +497,76 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= monsters[fighting].level; - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - if (fighting === 2) { - winGame(); - } else { - defeatMonster(); - } - } + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= monsters[fighting].level; + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + if (fighting === 2) { + winGame(); + } else { + defeatMonster(); + } + } } function dodge() { @@ -574,10 +574,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -586,15 +586,15 @@ function lose() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } ``` diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-116.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-116.md index 5d310b3d9d..1029031df8 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-116.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-116.md @@ -14,9 +14,9 @@ Change the if-else expression from the last challenge to use the ternary operato ```js if (age >= 18) { - adultFunction(); + adultFunction(); } else { - kidFunction(); + kidFunction(); } // The above if-else expression does the same thing as the following line @@ -70,22 +70,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -107,42 +107,42 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" - } + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" + } ]; // initialize buttons @@ -152,13 +152,13 @@ button3.onclick = fightDragon; function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -185,76 +185,76 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= monsters[fighting].level; - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - if (fighting === 2) { - winGame(); - } else { - defeatMonster(); - } - } + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= monsters[fighting].level; + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + if (fighting === 2) { + winGame(); + } else { + defeatMonster(); + } + } } function dodge() { @@ -262,10 +262,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -274,15 +274,15 @@ function lose() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } @@ -400,22 +400,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -437,42 +437,42 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" - } + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" + } ]; // initialize buttons @@ -480,15 +480,15 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -500,7 +500,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -515,72 +515,72 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= monsters[fighting].level; - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= monsters[fighting].level; + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { fighting === 2 ? winGame() : defeatMonster(); - } + } } function dodge() { @@ -588,10 +588,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -600,15 +600,15 @@ function lose() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } ``` diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-117.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-117.md index 914a1a0ef6..a8f0bf34a8 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-117.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-117.md @@ -56,22 +56,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -93,42 +93,42 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" - } + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" + } ]; // initialize buttons @@ -138,13 +138,13 @@ button3.onclick = fightDragon; function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -171,72 +171,72 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= monsters[fighting].level; - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= monsters[fighting].level; + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { fighting === 2 ? winGame() : defeatMonster(); - } + } } function dodge() { @@ -244,10 +244,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -256,15 +256,15 @@ function lose() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } @@ -382,22 +382,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -419,42 +419,42 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" - } + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" + } ]; // initialize buttons @@ -462,15 +462,15 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -482,7 +482,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -497,72 +497,72 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= monsters[fighting].level; - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= monsters[fighting].level; + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { fighting === 2 ? winGame() : defeatMonster(); - } + } } function dodge() { @@ -570,10 +570,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -586,15 +586,15 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } ``` diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-118.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-118.md index c523fd5be5..b71458286e 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-118.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-118.md @@ -57,22 +57,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -94,42 +94,42 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" - } + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" + } ]; // initialize buttons @@ -139,13 +139,13 @@ button3.onclick = fightDragon; function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -172,72 +172,72 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= monsters[fighting].level; - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= monsters[fighting].level; + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { fighting === 2 ? winGame() : defeatMonster(); - } + } } function dodge() { @@ -245,10 +245,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -261,15 +261,15 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } @@ -387,22 +387,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -424,41 +424,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -473,15 +473,15 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -493,7 +493,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -508,72 +508,72 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= monsters[fighting].level; - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= monsters[fighting].level; + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { fighting === 2 ? winGame() : defeatMonster(); - } + } } function dodge() { @@ -581,10 +581,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -597,15 +597,15 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } ``` diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-119.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-119.md index 691be04dad..a4e5efa3c9 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-119.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-119.md @@ -58,22 +58,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -95,41 +95,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -146,13 +146,13 @@ button3.onclick = fightDragon; function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -179,72 +179,72 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= monsters[fighting].level; - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= monsters[fighting].level; + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { fighting === 2 ? winGame() : defeatMonster(); - } + } } function dodge() { @@ -252,10 +252,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -268,15 +268,15 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } @@ -394,22 +394,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -431,41 +431,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -480,15 +480,15 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -500,7 +500,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -515,72 +515,72 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { fighting === 2 ? winGame() : defeatMonster(); - } + } } function dodge() { @@ -588,10 +588,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -604,15 +604,15 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } ``` diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-120.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-120.md index 75a9dd8a2c..d88c1ce177 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-120.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-120.md @@ -56,22 +56,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -93,41 +93,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -144,13 +144,13 @@ button3.onclick = fightDragon; function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -177,72 +177,72 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { fighting === 2 ? winGame() : defeatMonster(); - } + } } function dodge() { @@ -250,10 +250,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -266,15 +266,15 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } @@ -392,22 +392,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -429,41 +429,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -478,15 +478,15 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -498,7 +498,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -513,72 +513,72 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { fighting === 2 ? winGame() : defeatMonster(); - } + } } function getMonsterAttackValue(level) { @@ -589,10 +589,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -605,15 +605,15 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } ``` diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-121.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-121.md index ea302c2e16..7b559a82f4 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-121.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-121.md @@ -56,22 +56,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -93,41 +93,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -144,13 +144,13 @@ button3.onclick = fightDragon; function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -177,72 +177,72 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { fighting === 2 ? winGame() : defeatMonster(); - } + } } function getMonsterAttackValue(level) { @@ -254,10 +254,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -270,15 +270,15 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } @@ -396,22 +396,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -433,41 +433,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -482,15 +482,15 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -502,7 +502,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -517,72 +517,72 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { fighting === 2 ? winGame() : defeatMonster(); - } + } } function getMonsterAttackValue(level) { @@ -594,10 +594,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -610,15 +610,15 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } ``` diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-122.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-122.md index d26645770a..ce8fd55989 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-122.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-122.md @@ -58,22 +58,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -95,41 +95,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -146,13 +146,13 @@ button3.onclick = fightDragon; function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -179,72 +179,72 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { fighting === 2 ? winGame() : defeatMonster(); - } + } } function getMonsterAttackValue(level) { @@ -256,10 +256,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -272,15 +272,15 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } @@ -398,22 +398,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -435,41 +435,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -484,15 +484,15 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -504,7 +504,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -519,72 +519,72 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { fighting === 2 ? winGame() : defeatMonster(); - } + } } function getMonsterAttackValue(level) { @@ -597,10 +597,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -613,15 +613,15 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } ``` diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-123.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-123.md index 1441409d05..24566083db 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-123.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-123.md @@ -14,8 +14,8 @@ Here is an example of a function that returns a value: ```js function plusThree(num) { - let numPlusThree = num + 3; - return numPlusThree; + let numPlusThree = num + 3; + return numPlusThree; } const answer = plusThree(5); // 8 @@ -67,22 +67,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -104,41 +104,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -155,13 +155,13 @@ button3.onclick = fightDragon; function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -188,72 +188,72 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { fighting === 2 ? winGame() : defeatMonster(); - } + } } function getMonsterAttackValue(level) { @@ -266,10 +266,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -282,15 +282,15 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } @@ -408,22 +408,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -445,41 +445,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -494,15 +494,15 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -514,7 +514,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -529,72 +529,72 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { fighting === 2 ? winGame() : defeatMonster(); - } + } } function getMonsterAttackValue(level) { @@ -607,10 +607,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -623,15 +623,15 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } ``` diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-124.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-124.md index fee956a651..951a038629 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-124.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-124.md @@ -66,22 +66,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -103,41 +103,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -154,13 +154,13 @@ button3.onclick = fightDragon; function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -187,72 +187,72 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { fighting === 2 ? winGame() : defeatMonster(); - } + } } function getMonsterAttackValue(level) { @@ -266,10 +266,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -282,15 +282,15 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } @@ -408,22 +408,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -445,41 +445,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -494,15 +494,15 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -514,7 +514,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -529,72 +529,72 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { fighting === 2 ? winGame() : defeatMonster(); - } + } } function getMonsterAttackValue(level) { @@ -607,10 +607,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -623,15 +623,15 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } ``` diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-125.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-125.md index 7f8a5f54b0..3a2bd520f5 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-125.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-125.md @@ -64,22 +64,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -101,41 +101,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -152,13 +152,13 @@ button3.onclick = fightDragon; function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -185,72 +185,72 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { fighting === 2 ? winGame() : defeatMonster(); - } + } } function getMonsterAttackValue(level) { @@ -264,10 +264,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -280,15 +280,15 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } @@ -406,22 +406,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -443,41 +443,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -492,15 +492,15 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -512,7 +512,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -527,74 +527,74 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; health -= getMonsterAttackValue(monsters[fighting].level); if (isMonsterHit()) { - } - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { + } + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { fighting === 2 ? winGame() : defeatMonster(); - } + } } function getMonsterAttackValue(level) { @@ -607,10 +607,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -623,15 +623,15 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } ``` diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-126.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-126.md index 2ead7695e2..4f6ef320dc 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-126.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-126.md @@ -14,7 +14,7 @@ Here is an example of code in an `if` block that logs a message to the console: ```js if (isTrue()) { - console.log("It's true!"); + console.log("It's true!"); } ``` @@ -64,22 +64,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -101,41 +101,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -152,13 +152,13 @@ button3.onclick = fightDragon; function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -185,76 +185,76 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; health -= getMonsterAttackValue(monsters[fighting].level); if (isMonsterHit()) { } - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { fighting === 2 ? winGame() : defeatMonster(); - } + } } function getMonsterAttackValue(level) { @@ -268,10 +268,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -284,15 +284,15 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } @@ -410,22 +410,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -447,41 +447,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -496,15 +496,15 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -516,7 +516,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -531,74 +531,74 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; health -= getMonsterAttackValue(monsters[fighting].level); if (isMonsterHit()) { monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - } - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { + } + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { fighting === 2 ? winGame() : defeatMonster(); - } + } } function getMonsterAttackValue(level) { @@ -611,10 +611,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -627,15 +627,15 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } ``` diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-127.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-127.md index 97a64c54db..fbcf5863b5 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-127.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-127.md @@ -56,22 +56,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -93,41 +93,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -144,13 +144,13 @@ button3.onclick = fightDragon; function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -177,75 +177,75 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; health -= getMonsterAttackValue(monsters[fighting].level); if (isMonsterHit()) { monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; } - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { fighting === 2 ? winGame() : defeatMonster(); - } + } } function getMonsterAttackValue(level) { @@ -259,10 +259,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -275,15 +275,15 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } @@ -401,22 +401,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -438,41 +438,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -487,15 +487,15 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -507,7 +507,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -522,77 +522,77 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); - if (isMonsterHit()) { - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - } else { - text.innerText += " You miss."; - } - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - fighting === 2 ? winGame() : defeatMonster(); - } + if (isMonsterHit()) { + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + } else { + text.innerText += " You miss."; + } + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + fighting === 2 ? winGame() : defeatMonster(); + } } function getMonsterAttackValue(level) { @@ -605,10 +605,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -621,15 +621,15 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } ``` diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-128.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-128.md index cd6e0f66a8..0a7da3c6a6 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-128.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-128.md @@ -14,7 +14,7 @@ Here is a function that returns the result of a comparison: ```js function flipHeads() { - return Math.random() > .5; + return Math.random() > .5; } ``` @@ -64,22 +64,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -101,41 +101,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -152,13 +152,13 @@ button3.onclick = fightDragon; function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -185,77 +185,77 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); - if (isMonsterHit()) { - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - } else { - text.innerText += " You miss."; - } - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - fighting === 2 ? winGame() : defeatMonster(); - } + if (isMonsterHit()) { + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + } else { + text.innerText += " You miss."; + } + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + fighting === 2 ? winGame() : defeatMonster(); + } } function getMonsterAttackValue(level) { @@ -269,10 +269,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -285,15 +285,15 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } @@ -411,22 +411,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -448,41 +448,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -497,15 +497,15 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -517,7 +517,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -532,77 +532,77 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); - if (isMonsterHit()) { - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - } else { - text.innerText += " You miss."; - } - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - fighting === 2 ? winGame() : defeatMonster(); - } + if (isMonsterHit()) { + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + } else { + text.innerText += " You miss."; + } + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + fighting === 2 ? winGame() : defeatMonster(); + } } function getMonsterAttackValue(level) { @@ -611,7 +611,7 @@ function getMonsterAttackValue(level) { } function isMonsterHit() { - return Math.random() > .2; + return Math.random() > .2; } function dodge() { @@ -619,10 +619,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -635,15 +635,15 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } ``` diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-129.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-129.md index 165a22f910..3a7f484bab 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-129.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-129.md @@ -58,22 +58,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -95,41 +95,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" } { name: "win", @@ -146,13 +146,13 @@ button3.onclick = fightDragon; function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -179,77 +179,77 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); - if (isMonsterHit()) { - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - } else { - text.innerText += " You miss."; - } - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - fighting === 2 ? winGame() : defeatMonster(); - } + if (isMonsterHit()) { + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + } else { + text.innerText += " You miss."; + } + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + fighting === 2 ? winGame() : defeatMonster(); + } } function getMonsterAttackValue(level) { @@ -259,7 +259,7 @@ function getMonsterAttackValue(level) { } function isMonsterHit() { - return Math.random() > .2; + return Math.random() > .2; } function dodge() { @@ -267,10 +267,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -283,15 +283,15 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } @@ -409,22 +409,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -446,41 +446,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -495,15 +495,15 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -515,7 +515,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -530,77 +530,77 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); - if (isMonsterHit()) { - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - } else { - text.innerText += " You miss."; - } - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - fighting === 2 ? winGame() : defeatMonster(); - } + if (isMonsterHit()) { + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + } else { + text.innerText += " You miss."; + } + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + fighting === 2 ? winGame() : defeatMonster(); + } } function getMonsterAttackValue(level) { @@ -609,7 +609,7 @@ function getMonsterAttackValue(level) { } function isMonsterHit() { - return Math.random() > .2 || health < 20; + return Math.random() > .2 || health < 20; } function dodge() { @@ -617,10 +617,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -633,15 +633,15 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } ``` diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-130.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-130.md index a214dc1b8a..9dbbd574cf 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-130.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-130.md @@ -56,22 +56,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -93,41 +93,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -144,13 +144,13 @@ button3.onclick = fightDragon; function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -177,77 +177,77 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); - if (isMonsterHit()) { - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - } else { - text.innerText += " You miss."; - } - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - fighting === 2 ? winGame() : defeatMonster(); - } + if (isMonsterHit()) { + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + } else { + text.innerText += " You miss."; + } + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + fighting === 2 ? winGame() : defeatMonster(); + } } function getMonsterAttackValue(level) { @@ -257,7 +257,7 @@ function getMonsterAttackValue(level) { } function isMonsterHit() { - return Math.random() > .2 || health < 20; + return Math.random() > .2 || health < 20; } function dodge() { @@ -265,10 +265,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -281,15 +281,15 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } @@ -407,22 +407,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -444,41 +444,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -493,15 +493,15 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -513,7 +513,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -528,76 +528,76 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); - if (isMonsterHit()) { - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - } else { - text.innerText += " You miss."; - } - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - fighting === 2 ? winGame() : defeatMonster(); + if (isMonsterHit()) { + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + } else { + text.innerText += " You miss."; + } + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + fighting === 2 ? winGame() : defeatMonster(); } if (Math.random() <= .1) { } @@ -609,7 +609,7 @@ function getMonsterAttackValue(level) { } function isMonsterHit() { - return Math.random() > .2 || health < 20; + return Math.random() > .2 || health < 20; } function dodge() { @@ -617,10 +617,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -633,15 +633,15 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } ``` diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-131.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-131.md index 5a6afc8cee..31060bedbd 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-131.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-131.md @@ -64,22 +64,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -101,41 +101,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -152,13 +152,13 @@ button3.onclick = fightDragon; function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -185,76 +185,76 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); - if (isMonsterHit()) { - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - } else { - text.innerText += " You miss."; + if (isMonsterHit()) { + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + } else { + text.innerText += " You miss."; } - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - fighting === 2 ? winGame() : defeatMonster(); + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + fighting === 2 ? winGame() : defeatMonster(); } if (Math.random() <= .1) { @@ -269,7 +269,7 @@ function getMonsterAttackValue(level) { } function isMonsterHit() { - return Math.random() > .2 || health < 20; + return Math.random() > .2 || health < 20; } function dodge() { @@ -277,10 +277,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -293,15 +293,15 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } @@ -419,22 +419,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -456,41 +456,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -505,15 +505,15 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -525,7 +525,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -540,76 +540,76 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); - if (isMonsterHit()) { - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - } else { - text.innerText += " You miss."; - } - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - fighting === 2 ? winGame() : defeatMonster(); + if (isMonsterHit()) { + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + } else { + text.innerText += " You miss."; + } + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + fighting === 2 ? winGame() : defeatMonster(); } if (Math.random() <= .1) { @@ -623,7 +623,7 @@ function getMonsterAttackValue(level) { } function isMonsterHit() { - return Math.random() > .2 || health < 20; + return Math.random() > .2 || health < 20; } function dodge() { @@ -631,10 +631,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -647,15 +647,15 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } ``` diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-132.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-132.md index 668f182486..f2d9a250bf 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-132.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-132.md @@ -56,22 +56,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -93,41 +93,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -144,13 +144,13 @@ button3.onclick = fightDragon; function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -177,76 +177,76 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); - if (isMonsterHit()) { - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - } else { - text.innerText += " You miss."; - } - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - fighting === 2 ? winGame() : defeatMonster(); + if (isMonsterHit()) { + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + } else { + text.innerText += " You miss."; + } + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + fighting === 2 ? winGame() : defeatMonster(); } if (Math.random() <= .1) { @@ -261,7 +261,7 @@ function getMonsterAttackValue(level) { } function isMonsterHit() { - return Math.random() > .2 || health < 20; + return Math.random() > .2 || health < 20; } function dodge() { @@ -269,10 +269,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -285,15 +285,15 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } @@ -411,22 +411,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -448,41 +448,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -497,15 +497,15 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -517,7 +517,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -532,76 +532,76 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); - if (isMonsterHit()) { - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - } else { - text.innerText += " You miss."; - } - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - fighting === 2 ? winGame() : defeatMonster(); + if (isMonsterHit()) { + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + } else { + text.innerText += " You miss."; + } + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + fighting === 2 ? winGame() : defeatMonster(); } if (Math.random() <= .1) { text.innerText += " Your " + inventory.pop() + " breaks."; @@ -615,7 +615,7 @@ function getMonsterAttackValue(level) { } function isMonsterHit() { - return Math.random() > .2 || health < 20; + return Math.random() > .2 || health < 20; } function dodge() { @@ -623,10 +623,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -639,15 +639,15 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } ``` diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-133.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-133.md index f4d1a0b4c4..d70fde02b5 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-133.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-133.md @@ -16,7 +16,7 @@ Here is an example of an `if` expression with the conditions that `firstName` eq ```js if (firstName === "Quincy" && lastName !== "Larson") { - console.log("Cool name but not the creator of freeCodeCamp.org.") + console.log("Cool name but not the creator of freeCodeCamp.org.") } ``` @@ -66,22 +66,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -103,41 +103,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -154,13 +154,13 @@ button3.onclick = fightDragon; function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -187,76 +187,76 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); - if (isMonsterHit()) { - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - } else { - text.innerText += " You miss."; - } - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - fighting === 2 ? winGame() : defeatMonster(); + if (isMonsterHit()) { + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + } else { + text.innerText += " You miss."; + } + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + fighting === 2 ? winGame() : defeatMonster(); } if (Math.random() <= .1) { @@ -272,7 +272,7 @@ function getMonsterAttackValue(level) { } function isMonsterHit() { - return Math.random() > .2 || health < 20; + return Math.random() > .2 || health < 20; } function dodge() { @@ -280,10 +280,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -296,15 +296,15 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } @@ -422,22 +422,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -459,41 +459,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -508,15 +508,15 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -528,7 +528,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -543,76 +543,76 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); - if (isMonsterHit()) { - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - } else { - text.innerText += " You miss."; - } - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - fighting === 2 ? winGame() : defeatMonster(); + if (isMonsterHit()) { + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + } else { + text.innerText += " You miss."; + } + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + fighting === 2 ? winGame() : defeatMonster(); } if (Math.random() <= .1 && inventory.length !== 1) { text.innerText += " Your " + inventory.pop() + " breaks."; @@ -626,7 +626,7 @@ function getMonsterAttackValue(level) { } function isMonsterHit() { - return Math.random() > .2 || health < 20; + return Math.random() > .2 || health < 20; } function dodge() { @@ -634,10 +634,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -650,15 +650,15 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } ``` diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-134.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-134.md index 027db4f5b2..3d9c307ff1 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-134.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-134.md @@ -58,22 +58,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -95,41 +95,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -146,13 +146,13 @@ button3.onclick = fightDragon; function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -179,76 +179,76 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); - if (isMonsterHit()) { - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - } else { - text.innerText += " You miss."; - } - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - fighting === 2 ? winGame() : defeatMonster(); + if (isMonsterHit()) { + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + } else { + text.innerText += " You miss."; + } + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + fighting === 2 ? winGame() : defeatMonster(); } if (Math.random() <= .1 && inventory.length !== 1) { @@ -264,7 +264,7 @@ function getMonsterAttackValue(level) { } function isMonsterHit() { - return Math.random() > .2 || health < 20; + return Math.random() > .2 || health < 20; } function dodge() { @@ -272,10 +272,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -288,15 +288,15 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } @@ -414,22 +414,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -451,41 +451,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -500,15 +500,15 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -520,7 +520,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -535,76 +535,76 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); - if (isMonsterHit()) { - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - } else { - text.innerText += " You miss."; - } - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - fighting === 2 ? winGame() : defeatMonster(); + if (isMonsterHit()) { + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + } else { + text.innerText += " You miss."; + } + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + fighting === 2 ? winGame() : defeatMonster(); } if (Math.random() <= .1 && inventory.length !== 1) { text.innerText += " Your " + inventory.pop() + " breaks."; @@ -618,7 +618,7 @@ function getMonsterAttackValue(level) { } function isMonsterHit() { - return Math.random() > .2 || health < 20; + return Math.random() > .2 || health < 20; } function dodge() { @@ -626,10 +626,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -642,19 +642,19 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } function easterEgg() { - update(locations[7]); + update(locations[7]); } ``` diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-135.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-135.md index e43942f587..177c5cd410 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-135.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-135.md @@ -59,22 +59,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -96,41 +96,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -147,13 +147,13 @@ button3.onclick = fightDragon; function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -180,76 +180,76 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); - if (isMonsterHit()) { - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - } else { - text.innerText += " You miss."; - } - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - fighting === 2 ? winGame() : defeatMonster(); + if (isMonsterHit()) { + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + } else { + text.innerText += " You miss."; + } + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + fighting === 2 ? winGame() : defeatMonster(); } if (Math.random() <= .1 && inventory.length !== 1) { @@ -265,7 +265,7 @@ function getMonsterAttackValue(level) { } function isMonsterHit() { - return Math.random() > .2 || health < 20; + return Math.random() > .2 || health < 20; } function dodge() { @@ -273,10 +273,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -289,19 +289,19 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } function easterEgg() { - update(locations[7]); + update(locations[7]); } @@ -422,22 +422,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -459,41 +459,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -502,11 +502,11 @@ const locations = [ text: "You defeat the dragon! YOU WIN THE GAME! 🎉" }, { - name: "easter egg", - "button text": ["2", "8", "Go to town square?"], - "button functions": [pickTwo, pickEight, goTown], - text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" - } + name: "easter egg", + "button text": ["2", "8", "Go to town square?"], + "button functions": [pickTwo, pickEight, goTown], + text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" + } ]; // initialize buttons @@ -514,15 +514,15 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -534,7 +534,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -549,76 +549,76 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); - if (isMonsterHit()) { - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - } else { - text.innerText += " You miss."; - } - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - fighting === 2 ? winGame() : defeatMonster(); + if (isMonsterHit()) { + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + } else { + text.innerText += " You miss."; + } + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + fighting === 2 ? winGame() : defeatMonster(); } if (Math.random() <= .1 && inventory.length !== 1) { text.innerText += " Your " + inventory.pop() + " breaks."; @@ -632,7 +632,7 @@ function getMonsterAttackValue(level) { } function isMonsterHit() { - return Math.random() > .2 || health < 20; + return Math.random() > .2 || health < 20; } function dodge() { @@ -640,10 +640,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -656,19 +656,19 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } function easterEgg() { - update(locations[7]); + update(locations[7]); } ``` diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-136.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-136.md index 02b1f90b7c..52a0d952f3 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-136.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-136.md @@ -58,22 +58,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -95,41 +95,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -138,11 +138,11 @@ const locations = [ text: "You defeat the dragon! YOU WIN THE GAME! 🎉" }, { - name: "easter egg", - "button text": ["2", "8", "Go to town square?"], - "button functions": [pickTwo, pickEight, goTown], - text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" - } + name: "easter egg", + "button text": ["2", "8", "Go to town square?"], + "button functions": [pickTwo, pickEight, goTown], + text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" + } ]; // initialize buttons @@ -152,13 +152,13 @@ button3.onclick = fightDragon; function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -185,76 +185,76 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); - if (isMonsterHit()) { - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - } else { - text.innerText += " You miss."; - } - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - fighting === 2 ? winGame() : defeatMonster(); + if (isMonsterHit()) { + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + } else { + text.innerText += " You miss."; + } + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + fighting === 2 ? winGame() : defeatMonster(); } if (Math.random() <= .1 && inventory.length !== 1) { @@ -270,7 +270,7 @@ function getMonsterAttackValue(level) { } function isMonsterHit() { - return Math.random() > .2 || health < 20; + return Math.random() > .2 || health < 20; } function dodge() { @@ -278,10 +278,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -294,19 +294,19 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } function easterEgg() { - update(locations[7]); + update(locations[7]); } @@ -427,22 +427,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -464,41 +464,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -507,11 +507,11 @@ const locations = [ text: "You defeat the dragon! YOU WIN THE GAME! 🎉" }, { - name: "easter egg", - "button text": ["2", "8", "Go to town square?"], - "button functions": [pickTwo, pickEight, goTown], - text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" - } + name: "easter egg", + "button text": ["2", "8", "Go to town square?"], + "button functions": [pickTwo, pickEight, goTown], + text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" + } ]; // initialize buttons @@ -519,15 +519,15 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -539,7 +539,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -554,76 +554,76 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); - if (isMonsterHit()) { - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - } else { - text.innerText += " You miss."; - } - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - fighting === 2 ? winGame() : defeatMonster(); + if (isMonsterHit()) { + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + } else { + text.innerText += " You miss."; + } + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + fighting === 2 ? winGame() : defeatMonster(); } if (Math.random() <= .1 && inventory.length !== 1) { text.innerText += " Your " + inventory.pop() + " breaks."; @@ -637,7 +637,7 @@ function getMonsterAttackValue(level) { } function isMonsterHit() { - return Math.random() > .2 || health < 20; + return Math.random() > .2 || health < 20; } function dodge() { @@ -645,10 +645,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -661,19 +661,19 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } function easterEgg() { - update(locations[7]); + update(locations[7]); } function pickTwo() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-137.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-137.md index db4520b416..70542a4be7 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-137.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-137.md @@ -56,22 +56,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -93,41 +93,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -136,11 +136,11 @@ const locations = [ text: "You defeat the dragon! YOU WIN THE GAME! 🎉" }, { - name: "easter egg", - "button text": ["2", "8", "Go to town square?"], - "button functions": [pickTwo, pickEight, goTown], - text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" - } + name: "easter egg", + "button text": ["2", "8", "Go to town square?"], + "button functions": [pickTwo, pickEight, goTown], + text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" + } ]; // initialize buttons @@ -150,13 +150,13 @@ button3.onclick = fightDragon; function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -183,76 +183,76 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); - if (isMonsterHit()) { - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - } else { - text.innerText += " You miss."; - } - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - fighting === 2 ? winGame() : defeatMonster(); + if (isMonsterHit()) { + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + } else { + text.innerText += " You miss."; + } + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + fighting === 2 ? winGame() : defeatMonster(); } if (Math.random() <= .1 && inventory.length !== 1) { @@ -268,7 +268,7 @@ function getMonsterAttackValue(level) { } function isMonsterHit() { - return Math.random() > .2 || health < 20; + return Math.random() > .2 || health < 20; } function dodge() { @@ -276,10 +276,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -292,19 +292,19 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } function easterEgg() { - update(locations[7]); + update(locations[7]); } function pickTwo() { @@ -430,22 +430,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -467,41 +467,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -510,11 +510,11 @@ const locations = [ text: "You defeat the dragon! YOU WIN THE GAME! 🎉" }, { - name: "easter egg", - "button text": ["2", "8", "Go to town square?"], - "button functions": [pickTwo, pickEight, goTown], - text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" - } + name: "easter egg", + "button text": ["2", "8", "Go to town square?"], + "button functions": [pickTwo, pickEight, goTown], + text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" + } ]; // initialize buttons @@ -522,15 +522,15 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -542,7 +542,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -557,76 +557,76 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); - if (isMonsterHit()) { - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - } else { - text.innerText += " You miss."; - } - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - fighting === 2 ? winGame() : defeatMonster(); + if (isMonsterHit()) { + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + } else { + text.innerText += " You miss."; + } + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + fighting === 2 ? winGame() : defeatMonster(); } if (Math.random() <= .1 && inventory.length !== 1) { text.innerText += " Your " + inventory.pop() + " breaks."; @@ -640,7 +640,7 @@ function getMonsterAttackValue(level) { } function isMonsterHit() { - return Math.random() > .2 || health < 20; + return Math.random() > .2 || health < 20; } function dodge() { @@ -648,10 +648,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -664,19 +664,19 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } function easterEgg() { - update(locations[7]); + update(locations[7]); } function pickTwo() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-138.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-138.md index 8f14cf42ce..905c30cb72 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-138.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-138.md @@ -56,22 +56,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -93,41 +93,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -136,11 +136,11 @@ const locations = [ text: "You defeat the dragon! YOU WIN THE GAME! 🎉" }, { - name: "easter egg", - "button text": ["2", "8", "Go to town square?"], - "button functions": [pickTwo, pickEight, goTown], - text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" - } + name: "easter egg", + "button text": ["2", "8", "Go to town square?"], + "button functions": [pickTwo, pickEight, goTown], + text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" + } ]; // initialize buttons @@ -150,13 +150,13 @@ button3.onclick = fightDragon; function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -183,76 +183,76 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); - if (isMonsterHit()) { - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - } else { - text.innerText += " You miss."; - } - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - fighting === 2 ? winGame() : defeatMonster(); + if (isMonsterHit()) { + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + } else { + text.innerText += " You miss."; + } + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + fighting === 2 ? winGame() : defeatMonster(); } if (Math.random() <= .1 && inventory.length !== 1) { @@ -268,7 +268,7 @@ function getMonsterAttackValue(level) { } function isMonsterHit() { - return Math.random() > .2 || health < 20; + return Math.random() > .2 || health < 20; } function dodge() { @@ -276,10 +276,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -292,19 +292,19 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } function easterEgg() { - update(locations[7]); + update(locations[7]); } function pickTwo() { @@ -434,22 +434,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -471,41 +471,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -514,11 +514,11 @@ const locations = [ text: "You defeat the dragon! YOU WIN THE GAME! 🎉" }, { - name: "easter egg", - "button text": ["2", "8", "Go to town square?"], - "button functions": [pickTwo, pickEight, goTown], - text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" - } + name: "easter egg", + "button text": ["2", "8", "Go to town square?"], + "button functions": [pickTwo, pickEight, goTown], + text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" + } ]; // initialize buttons @@ -526,15 +526,15 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -546,7 +546,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -561,76 +561,76 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); - if (isMonsterHit()) { - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - } else { - text.innerText += " You miss."; - } - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - fighting === 2 ? winGame() : defeatMonster(); + if (isMonsterHit()) { + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + } else { + text.innerText += " You miss."; + } + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + fighting === 2 ? winGame() : defeatMonster(); } if (Math.random() <= .1 && inventory.length !== 1) { text.innerText += " Your " + inventory.pop() + " breaks."; @@ -644,7 +644,7 @@ function getMonsterAttackValue(level) { } function isMonsterHit() { - return Math.random() > .2 || health < 20; + return Math.random() > .2 || health < 20; } function dodge() { @@ -652,10 +652,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -668,19 +668,19 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } function easterEgg() { - update(locations[7]); + update(locations[7]); } function pickTwo() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-139.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-139.md index f9cf083685..dc75dd5334 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-139.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-139.md @@ -35,7 +35,7 @@ while(i < 5) { ```yml tests: - text: See description above for instructions. - testString: assert(pick.toString().replace(/\s/g, '').includes('var_LP=Date.now();while(numbers.length<10){if(Date.now()-_LP>100)break;}')); # Take loop protect into account + testString: assert(pick.toString().replace(/\s/g, '').includes('while(numbers.length<10){if(Date.now()-_LP>100){')); # Take loop protect into account ``` @@ -68,22 +68,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -105,41 +105,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -148,11 +148,11 @@ const locations = [ text: "You defeat the dragon! YOU WIN THE GAME! 🎉" }, { - name: "easter egg", - "button text": ["2", "8", "Go to town square?"], - "button functions": [pickTwo, pickEight, goTown], - text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" - } + name: "easter egg", + "button text": ["2", "8", "Go to town square?"], + "button functions": [pickTwo, pickEight, goTown], + text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" + } ]; // initialize buttons @@ -162,13 +162,13 @@ button3.onclick = fightDragon; function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -195,76 +195,76 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); - if (isMonsterHit()) { - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - } else { - text.innerText += " You miss."; - } - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - fighting === 2 ? winGame() : defeatMonster(); + if (isMonsterHit()) { + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + } else { + text.innerText += " You miss."; + } + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + fighting === 2 ? winGame() : defeatMonster(); } if (Math.random() <= .1 && inventory.length !== 1) { @@ -280,7 +280,7 @@ function getMonsterAttackValue(level) { } function isMonsterHit() { - return Math.random() > .2 || health < 20; + return Math.random() > .2 || health < 20; } function dodge() { @@ -288,10 +288,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -304,19 +304,19 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } function easterEgg() { - update(locations[7]); + update(locations[7]); } function pickTwo() { @@ -446,22 +446,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -483,41 +483,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -526,11 +526,11 @@ const locations = [ text: "You defeat the dragon! YOU WIN THE GAME! 🎉" }, { - name: "easter egg", - "button text": ["2", "8", "Go to town square?"], - "button functions": [pickTwo, pickEight, goTown], - text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" - } + name: "easter egg", + "button text": ["2", "8", "Go to town square?"], + "button functions": [pickTwo, pickEight, goTown], + text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" + } ]; // initialize buttons @@ -538,15 +538,15 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -558,7 +558,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -573,76 +573,76 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); - if (isMonsterHit()) { - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - } else { - text.innerText += " You miss."; - } - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - fighting === 2 ? winGame() : defeatMonster(); + if (isMonsterHit()) { + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + } else { + text.innerText += " You miss."; + } + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + fighting === 2 ? winGame() : defeatMonster(); } if (Math.random() <= .1 && inventory.length !== 1) { text.innerText += " Your " + inventory.pop() + " breaks."; @@ -656,7 +656,7 @@ function getMonsterAttackValue(level) { } function isMonsterHit() { - return Math.random() > .2 || health < 20; + return Math.random() > .2 || health < 20; } function dodge() { @@ -664,10 +664,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -680,19 +680,19 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } function easterEgg() { - update(locations[7]); + update(locations[7]); } function pickTwo() { @@ -704,10 +704,10 @@ function pickEight() { } function pick(guess) { - let numbers = []; - while(numbers.length < 10) { + let numbers = []; + while(numbers.length < 10) { - } + } } ``` diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-140.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-140.md index 5d3acab75d..aa9b57e0b8 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-140.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-140.md @@ -23,7 +23,7 @@ Inside the `while` loop, push a random number between 0 and 10 onto the end of t ```yml tests: - text: See description above for instructions. - testString: assert(pick.toString().replace(/\s/g, '').includes('while(numbers.length<10){if(Date.now()-_LP>100)break;numbers.push(Math.floor(Math.random()*11));}')); # Take loop protect into account + testString: assert(pick.toString().replace(/\s/g, '').includes('numbers.push(Math.floor(Math.random()*11));}')); # Take loop protect into account ``` @@ -56,22 +56,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -93,41 +93,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -136,11 +136,11 @@ const locations = [ text: "You defeat the dragon! YOU WIN THE GAME! 🎉" }, { - name: "easter egg", - "button text": ["2", "8", "Go to town square?"], - "button functions": [pickTwo, pickEight, goTown], - text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" - } + name: "easter egg", + "button text": ["2", "8", "Go to town square?"], + "button functions": [pickTwo, pickEight, goTown], + text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" + } ]; // initialize buttons @@ -150,13 +150,13 @@ button3.onclick = fightDragon; function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -183,76 +183,76 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); - if (isMonsterHit()) { - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - } else { - text.innerText += " You miss."; - } - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - fighting === 2 ? winGame() : defeatMonster(); + if (isMonsterHit()) { + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + } else { + text.innerText += " You miss."; + } + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + fighting === 2 ? winGame() : defeatMonster(); } if (Math.random() <= .1 && inventory.length !== 1) { @@ -268,7 +268,7 @@ function getMonsterAttackValue(level) { } function isMonsterHit() { - return Math.random() > .2 || health < 20; + return Math.random() > .2 || health < 20; } function dodge() { @@ -276,10 +276,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -292,19 +292,19 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } function easterEgg() { - update(locations[7]); + update(locations[7]); } function pickTwo() { @@ -316,10 +316,10 @@ function pickEight() { } function pick(guess) { - let numbers = []; - while(numbers.length < 10) { + let numbers = []; + while(numbers.length < 10) { - } + } } @@ -437,22 +437,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -474,41 +474,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -517,11 +517,11 @@ const locations = [ text: "You defeat the dragon! YOU WIN THE GAME! 🎉" }, { - name: "easter egg", - "button text": ["2", "8", "Go to town square?"], - "button functions": [pickTwo, pickEight, goTown], - text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" - } + name: "easter egg", + "button text": ["2", "8", "Go to town square?"], + "button functions": [pickTwo, pickEight, goTown], + text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" + } ]; // initialize buttons @@ -529,15 +529,15 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -549,7 +549,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -564,76 +564,76 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); - if (isMonsterHit()) { - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - } else { - text.innerText += " You miss."; - } - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - fighting === 2 ? winGame() : defeatMonster(); + if (isMonsterHit()) { + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + } else { + text.innerText += " You miss."; + } + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + fighting === 2 ? winGame() : defeatMonster(); } if (Math.random() <= .1 && inventory.length !== 1) { text.innerText += " Your " + inventory.pop() + " breaks."; @@ -647,7 +647,7 @@ function getMonsterAttackValue(level) { } function isMonsterHit() { - return Math.random() > .2 || health < 20; + return Math.random() > .2 || health < 20; } function dodge() { @@ -655,10 +655,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -671,19 +671,19 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } function easterEgg() { - update(locations[7]); + update(locations[7]); } function pickTwo() { @@ -695,10 +695,10 @@ function pickEight() { } function pick(guess) { - let numbers = []; - while(numbers.length < 10) { + let numbers = []; + while(numbers.length < 10) { numbers.push(Math.floor(Math.random() * 11)); - } + } } ``` diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-141.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-141.md index f050965281..7df771be76 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-141.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-141.md @@ -56,22 +56,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -93,41 +93,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -136,11 +136,11 @@ const locations = [ text: "You defeat the dragon! YOU WIN THE GAME! 🎉" }, { - name: "easter egg", - "button text": ["2", "8", "Go to town square?"], - "button functions": [pickTwo, pickEight, goTown], - text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" - } + name: "easter egg", + "button text": ["2", "8", "Go to town square?"], + "button functions": [pickTwo, pickEight, goTown], + text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" + } ]; // initialize buttons @@ -150,13 +150,13 @@ button3.onclick = fightDragon; function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -183,76 +183,76 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); - if (isMonsterHit()) { - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - } else { - text.innerText += " You miss."; - } - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - fighting === 2 ? winGame() : defeatMonster(); + if (isMonsterHit()) { + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + } else { + text.innerText += " You miss."; + } + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + fighting === 2 ? winGame() : defeatMonster(); } if (Math.random() <= .1 && inventory.length !== 1) { @@ -268,7 +268,7 @@ function getMonsterAttackValue(level) { } function isMonsterHit() { - return Math.random() > .2 || health < 20; + return Math.random() > .2 || health < 20; } function dodge() { @@ -276,10 +276,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -292,19 +292,19 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } function easterEgg() { - update(locations[7]); + update(locations[7]); } function pickTwo() { @@ -316,10 +316,10 @@ function pickEight() { } function pick(guess) { - let numbers = []; - while(numbers.length < 10) { + let numbers = []; + while(numbers.length < 10) { numbers.push(Math.floor(Math.random() * 11)); - } + } } @@ -437,22 +437,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -474,41 +474,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -517,11 +517,11 @@ const locations = [ text: "You defeat the dragon! YOU WIN THE GAME! 🎉" }, { - name: "easter egg", - "button text": ["2", "8", "Go to town square?"], - "button functions": [pickTwo, pickEight, goTown], - text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" - } + name: "easter egg", + "button text": ["2", "8", "Go to town square?"], + "button functions": [pickTwo, pickEight, goTown], + text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" + } ]; // initialize buttons @@ -529,15 +529,15 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -549,7 +549,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -564,76 +564,76 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); - if (isMonsterHit()) { - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - } else { - text.innerText += " You miss."; - } - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - fighting === 2 ? winGame() : defeatMonster(); + if (isMonsterHit()) { + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + } else { + text.innerText += " You miss."; + } + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + fighting === 2 ? winGame() : defeatMonster(); } if (Math.random() <= .1 && inventory.length !== 1) { text.innerText += " Your " + inventory.pop() + " breaks."; @@ -647,7 +647,7 @@ function getMonsterAttackValue(level) { } function isMonsterHit() { - return Math.random() > .2 || health < 20; + return Math.random() > .2 || health < 20; } function dodge() { @@ -655,10 +655,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -671,19 +671,19 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } function easterEgg() { - update(locations[7]); + update(locations[7]); } function pickTwo() { @@ -695,12 +695,12 @@ function pickEight() { } function pick(guess) { - let numbers = []; - while(numbers.length < 10) { - numbers.push(Math.floor(Math.random() * 11)); - } + let numbers = []; + while(numbers.length < 10) { + numbers.push(Math.floor(Math.random() * 11)); + } - text.innerText = "You picked " + guess + ". Here are the random numbers:"; + text.innerText = "You picked " + guess + ". Here are the random numbers:"; } ``` diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-142.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-142.md index 91b5c22287..5c6c9922c7 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-142.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-142.md @@ -56,22 +56,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -93,41 +93,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -136,11 +136,11 @@ const locations = [ text: "You defeat the dragon! YOU WIN THE GAME! 🎉" }, { - name: "easter egg", - "button text": ["2", "8", "Go to town square?"], - "button functions": [pickTwo, pickEight, goTown], - text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" - } + name: "easter egg", + "button text": ["2", "8", "Go to town square?"], + "button functions": [pickTwo, pickEight, goTown], + text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" + } ]; // initialize buttons @@ -150,13 +150,13 @@ button3.onclick = fightDragon; function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -183,76 +183,76 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); - if (isMonsterHit()) { - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - } else { - text.innerText += " You miss."; - } - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - fighting === 2 ? winGame() : defeatMonster(); + if (isMonsterHit()) { + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + } else { + text.innerText += " You miss."; + } + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + fighting === 2 ? winGame() : defeatMonster(); } if (Math.random() <= .1 && inventory.length !== 1) { @@ -268,7 +268,7 @@ function getMonsterAttackValue(level) { } function isMonsterHit() { - return Math.random() > .2 || health < 20; + return Math.random() > .2 || health < 20; } function dodge() { @@ -276,10 +276,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -292,19 +292,19 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } function easterEgg() { - update(locations[7]); + update(locations[7]); } function pickTwo() { @@ -316,12 +316,12 @@ function pickEight() { } function pick(guess) { - let numbers = []; - while(numbers.length < 10) { - numbers.push(Math.floor(Math.random() * 11)); - } + let numbers = []; + while(numbers.length < 10) { + numbers.push(Math.floor(Math.random() * 11)); + } - text.innerText = "You picked " + guess + ". Here are the random numbers:"; + text.innerText = "You picked " + guess + ". Here are the random numbers:"; } @@ -439,22 +439,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -476,41 +476,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -519,11 +519,11 @@ const locations = [ text: "You defeat the dragon! YOU WIN THE GAME! 🎉" }, { - name: "easter egg", - "button text": ["2", "8", "Go to town square?"], - "button functions": [pickTwo, pickEight, goTown], - text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" - } + name: "easter egg", + "button text": ["2", "8", "Go to town square?"], + "button functions": [pickTwo, pickEight, goTown], + text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" + } ]; // initialize buttons @@ -531,15 +531,15 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -551,7 +551,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -566,76 +566,76 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); - if (isMonsterHit()) { - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - } else { - text.innerText += " You miss."; - } - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - fighting === 2 ? winGame() : defeatMonster(); + if (isMonsterHit()) { + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + } else { + text.innerText += " You miss."; + } + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + fighting === 2 ? winGame() : defeatMonster(); } if (Math.random() <= .1 && inventory.length !== 1) { text.innerText += " Your " + inventory.pop() + " breaks."; @@ -649,7 +649,7 @@ function getMonsterAttackValue(level) { } function isMonsterHit() { - return Math.random() > .2 || health < 20; + return Math.random() > .2 || health < 20; } function dodge() { @@ -657,10 +657,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -673,19 +673,19 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } function easterEgg() { - update(locations[7]); + update(locations[7]); } function pickTwo() { @@ -697,12 +697,12 @@ function pickEight() { } function pick(guess) { - let numbers = []; - while(numbers.length < 10) { - numbers.push(Math.floor(Math.random() * 11)); - } + let numbers = []; + while(numbers.length < 10) { + numbers.push(Math.floor(Math.random() * 11)); + } - text.innerText = "You picked " + guess + ". Here are the random numbers:\n"; + text.innerText = "You picked " + guess + ". Here are the random numbers:\n"; } ``` diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-143.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-143.md index 5253ab9b3e..8f026a536e 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-143.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-143.md @@ -31,7 +31,7 @@ for (let x = 1; x < 5; x++) { ```yml tests: - text: See description above for instructions. - testString: assert(pick.toString().replace(/\s/g, '').includes('for(varx=1;x<5;x++){if(Date.now()-_LP2>100)break;}')); # Also test for automatic loop protection + testString: assert(pick.toString().replace(/\s/g, '').includes('for(varx=1;x<5;x++){')); # Also test for automatic loop protection ``` @@ -64,22 +64,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -101,41 +101,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -144,11 +144,11 @@ const locations = [ text: "You defeat the dragon! YOU WIN THE GAME! 🎉" }, { - name: "easter egg", - "button text": ["2", "8", "Go to town square?"], - "button functions": [pickTwo, pickEight, goTown], - text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" - } + name: "easter egg", + "button text": ["2", "8", "Go to town square?"], + "button functions": [pickTwo, pickEight, goTown], + text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" + } ]; // initialize buttons @@ -158,13 +158,13 @@ button3.onclick = fightDragon; function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -191,76 +191,76 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); - if (isMonsterHit()) { - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - } else { - text.innerText += " You miss."; - } - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - fighting === 2 ? winGame() : defeatMonster(); + if (isMonsterHit()) { + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + } else { + text.innerText += " You miss."; + } + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + fighting === 2 ? winGame() : defeatMonster(); } if (Math.random() <= .1 && inventory.length !== 1) { @@ -276,7 +276,7 @@ function getMonsterAttackValue(level) { } function isMonsterHit() { - return Math.random() > .2 || health < 20; + return Math.random() > .2 || health < 20; } function dodge() { @@ -284,10 +284,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -300,19 +300,19 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } function easterEgg() { - update(locations[7]); + update(locations[7]); } function pickTwo() { @@ -324,12 +324,12 @@ function pickEight() { } function pick(guess) { - let numbers = []; - while(numbers.length < 10) { - numbers.push(Math.floor(Math.random() * 11)); - } + let numbers = []; + while(numbers.length < 10) { + numbers.push(Math.floor(Math.random() * 11)); + } - text.innerText = "You picked " + guess + ". Here are the random numbers:\n"; + text.innerText = "You picked " + guess + ". Here are the random numbers:\n"; } @@ -447,22 +447,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -484,41 +484,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -527,11 +527,11 @@ const locations = [ text: "You defeat the dragon! YOU WIN THE GAME! 🎉" }, { - name: "easter egg", - "button text": ["2", "8", "Go to town square?"], - "button functions": [pickTwo, pickEight, goTown], - text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" - } + name: "easter egg", + "button text": ["2", "8", "Go to town square?"], + "button functions": [pickTwo, pickEight, goTown], + text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" + } ]; // initialize buttons @@ -539,15 +539,15 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -559,7 +559,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -574,76 +574,76 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); - if (isMonsterHit()) { - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - } else { - text.innerText += " You miss."; - } - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - fighting === 2 ? winGame() : defeatMonster(); + if (isMonsterHit()) { + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + } else { + text.innerText += " You miss."; + } + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + fighting === 2 ? winGame() : defeatMonster(); } if (Math.random() <= .1 && inventory.length !== 1) { text.innerText += " Your " + inventory.pop() + " breaks."; @@ -657,7 +657,7 @@ function getMonsterAttackValue(level) { } function isMonsterHit() { - return Math.random() > .2 || health < 20; + return Math.random() > .2 || health < 20; } function dodge() { @@ -665,10 +665,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -681,19 +681,19 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } function easterEgg() { - update(locations[7]); + update(locations[7]); } function pickTwo() { @@ -705,10 +705,10 @@ function pickEight() { } function pick(guess) { - let numbers = []; - while(numbers.length < 10) { - numbers.push(Math.floor(Math.random() * 11)); - } + let numbers = []; + while(numbers.length < 10) { + numbers.push(Math.floor(Math.random() * 11)); + } text.innerText = "You picked " + guess + ". Here are the random numbers:\n"; diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-144.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-144.md index 0727a53f54..75c77bbda0 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-144.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-144.md @@ -27,7 +27,7 @@ Many `for` loops use `i` as an initializer and start from 0, so change `let x = ```yml tests: - text: See description above for instructions. - testString: assert(pick.toString().replace(/\s/g, '').includes('for(vari=0;x<5;x++){if(Date.now()-_LP2>100)break;}')); # Also test for automatic loop protection + testString: assert(pick.toString().replace(/\s/g, '').includes('for(vari=0;x<5;x++){')); # Also test for automatic loop protection ``` @@ -60,22 +60,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -97,41 +97,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -140,11 +140,11 @@ const locations = [ text: "You defeat the dragon! YOU WIN THE GAME! 🎉" }, { - name: "easter egg", - "button text": ["2", "8", "Go to town square?"], - "button functions": [pickTwo, pickEight, goTown], - text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" - } + name: "easter egg", + "button text": ["2", "8", "Go to town square?"], + "button functions": [pickTwo, pickEight, goTown], + text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" + } ]; // initialize buttons @@ -154,13 +154,13 @@ button3.onclick = fightDragon; function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -187,76 +187,76 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); - if (isMonsterHit()) { - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - } else { - text.innerText += " You miss."; - } - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - fighting === 2 ? winGame() : defeatMonster(); + if (isMonsterHit()) { + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + } else { + text.innerText += " You miss."; + } + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + fighting === 2 ? winGame() : defeatMonster(); } if (Math.random() <= .1 && inventory.length !== 1) { @@ -272,7 +272,7 @@ function getMonsterAttackValue(level) { } function isMonsterHit() { - return Math.random() > .2 || health < 20; + return Math.random() > .2 || health < 20; } function dodge() { @@ -280,10 +280,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -296,19 +296,19 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } function easterEgg() { - update(locations[7]); + update(locations[7]); } function pickTwo() { @@ -320,10 +320,10 @@ function pickEight() { } function pick(guess) { - let numbers = []; - while(numbers.length < 10) { - numbers.push(Math.floor(Math.random() * 11)); - } + let numbers = []; + while(numbers.length < 10) { + numbers.push(Math.floor(Math.random() * 11)); + } text.innerText = "You picked " + guess + ". Here are the random numbers:\n"; @@ -447,22 +447,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -484,41 +484,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -527,11 +527,11 @@ const locations = [ text: "You defeat the dragon! YOU WIN THE GAME! 🎉" }, { - name: "easter egg", - "button text": ["2", "8", "Go to town square?"], - "button functions": [pickTwo, pickEight, goTown], - text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" - } + name: "easter egg", + "button text": ["2", "8", "Go to town square?"], + "button functions": [pickTwo, pickEight, goTown], + text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" + } ]; // initialize buttons @@ -539,15 +539,15 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -559,7 +559,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -574,76 +574,76 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); - if (isMonsterHit()) { - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - } else { - text.innerText += " You miss."; - } - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - fighting === 2 ? winGame() : defeatMonster(); + if (isMonsterHit()) { + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + } else { + text.innerText += " You miss."; + } + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + fighting === 2 ? winGame() : defeatMonster(); } if (Math.random() <= .1 && inventory.length !== 1) { text.innerText += " Your " + inventory.pop() + " breaks."; @@ -657,7 +657,7 @@ function getMonsterAttackValue(level) { } function isMonsterHit() { - return Math.random() > .2 || health < 20; + return Math.random() > .2 || health < 20; } function dodge() { @@ -665,10 +665,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -681,19 +681,19 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } function easterEgg() { - update(locations[7]); + update(locations[7]); } function pickTwo() { @@ -705,10 +705,10 @@ function pickEight() { } function pick(guess) { - let numbers = []; - while(numbers.length < 10) { - numbers.push(Math.floor(Math.random() * 11)); - } + let numbers = []; + while(numbers.length < 10) { + numbers.push(Math.floor(Math.random() * 11)); + } text.innerText = "You picked " + guess + ". Here are the random numbers:\n"; diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-145.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-145.md index a887ce9fa2..f1df992950 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-145.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-145.md @@ -25,7 +25,7 @@ We want the loop to run 10 times, so change `x < 5` to `i < 10`. ```yml tests: - text: See description above for instructions. - testString: assert(pick.toString().replace(/\s/g, '').includes('for(vari=0;i<10;x++){if(Date.now()-_LP2>100)break;}')); # Also test for automatic loop protection + testString: assert(pick.toString().replace(/\s/g, '').includes('for(vari=0;i<10;x++){')); # Also test for automatic loop protection ``` @@ -58,22 +58,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -95,41 +95,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -138,11 +138,11 @@ const locations = [ text: "You defeat the dragon! YOU WIN THE GAME! 🎉" }, { - name: "easter egg", - "button text": ["2", "8", "Go to town square?"], - "button functions": [pickTwo, pickEight, goTown], - text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" - } + name: "easter egg", + "button text": ["2", "8", "Go to town square?"], + "button functions": [pickTwo, pickEight, goTown], + text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" + } ]; // initialize buttons @@ -152,13 +152,13 @@ button3.onclick = fightDragon; function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -185,76 +185,76 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); - if (isMonsterHit()) { - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - } else { - text.innerText += " You miss."; - } - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - fighting === 2 ? winGame() : defeatMonster(); + if (isMonsterHit()) { + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + } else { + text.innerText += " You miss."; + } + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + fighting === 2 ? winGame() : defeatMonster(); } if (Math.random() <= .1 && inventory.length !== 1) { @@ -270,7 +270,7 @@ function getMonsterAttackValue(level) { } function isMonsterHit() { - return Math.random() > .2 || health < 20; + return Math.random() > .2 || health < 20; } function dodge() { @@ -278,10 +278,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -294,19 +294,19 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } function easterEgg() { - update(locations[7]); + update(locations[7]); } function pickTwo() { @@ -318,10 +318,10 @@ function pickEight() { } function pick(guess) { - let numbers = []; - while(numbers.length < 10) { - numbers.push(Math.floor(Math.random() * 11)); - } + let numbers = []; + while(numbers.length < 10) { + numbers.push(Math.floor(Math.random() * 11)); + } text.innerText = "You picked " + guess + ". Here are the random numbers:\n"; @@ -445,22 +445,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -482,41 +482,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -525,11 +525,11 @@ const locations = [ text: "You defeat the dragon! YOU WIN THE GAME! 🎉" }, { - name: "easter egg", - "button text": ["2", "8", "Go to town square?"], - "button functions": [pickTwo, pickEight, goTown], - text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" - } + name: "easter egg", + "button text": ["2", "8", "Go to town square?"], + "button functions": [pickTwo, pickEight, goTown], + text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" + } ]; // initialize buttons @@ -537,15 +537,15 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -557,7 +557,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -572,76 +572,76 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); - if (isMonsterHit()) { - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - } else { - text.innerText += " You miss."; - } - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - fighting === 2 ? winGame() : defeatMonster(); + if (isMonsterHit()) { + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + } else { + text.innerText += " You miss."; + } + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + fighting === 2 ? winGame() : defeatMonster(); } if (Math.random() <= .1 && inventory.length !== 1) { text.innerText += " Your " + inventory.pop() + " breaks."; @@ -655,7 +655,7 @@ function getMonsterAttackValue(level) { } function isMonsterHit() { - return Math.random() > .2 || health < 20; + return Math.random() > .2 || health < 20; } function dodge() { @@ -663,10 +663,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -679,19 +679,19 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } function easterEgg() { - update(locations[7]); + update(locations[7]); } function pickTwo() { @@ -703,10 +703,10 @@ function pickEight() { } function pick(guess) { - let numbers = []; - while(numbers.length < 10) { - numbers.push(Math.floor(Math.random() * 11)); - } + let numbers = []; + while(numbers.length < 10) { + numbers.push(Math.floor(Math.random() * 11)); + } text.innerText = "You picked " + guess + ". Here are the random numbers:\n"; diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-146.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-146.md index dbf96091a8..d26f4873f6 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-146.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-146.md @@ -25,7 +25,7 @@ Since we changed the initializer from `x` to `i`, change `x++` to `i++`. This wi ```yml tests: - text: See description above for instructions. - testString: assert(pick.toString().replace(/\s/g, '').includes('for(vari=0;i<10;i++){if(Date.now()-_LP2>100)break;}')); # Also test for automatic loop protection + testString: assert(pick.toString().replace(/\s/g, '').includes('for(vari=0;i<10;i++){')); # Also test for automatic loop protection ``` @@ -58,22 +58,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -95,41 +95,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -138,11 +138,11 @@ const locations = [ text: "You defeat the dragon! YOU WIN THE GAME! 🎉" }, { - name: "easter egg", - "button text": ["2", "8", "Go to town square?"], - "button functions": [pickTwo, pickEight, goTown], - text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" - } + name: "easter egg", + "button text": ["2", "8", "Go to town square?"], + "button functions": [pickTwo, pickEight, goTown], + text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" + } ]; // initialize buttons @@ -152,13 +152,13 @@ button3.onclick = fightDragon; function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -185,76 +185,76 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); - if (isMonsterHit()) { - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - } else { - text.innerText += " You miss."; - } - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - fighting === 2 ? winGame() : defeatMonster(); + if (isMonsterHit()) { + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + } else { + text.innerText += " You miss."; + } + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + fighting === 2 ? winGame() : defeatMonster(); } if (Math.random() <= .1 && inventory.length !== 1) { @@ -270,7 +270,7 @@ function getMonsterAttackValue(level) { } function isMonsterHit() { - return Math.random() > .2 || health < 20; + return Math.random() > .2 || health < 20; } function dodge() { @@ -278,10 +278,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -294,19 +294,19 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } function easterEgg() { - update(locations[7]); + update(locations[7]); } function pickTwo() { @@ -318,10 +318,10 @@ function pickEight() { } function pick(guess) { - let numbers = []; - while(numbers.length < 10) { - numbers.push(Math.floor(Math.random() * 11)); - } + let numbers = []; + while(numbers.length < 10) { + numbers.push(Math.floor(Math.random() * 11)); + } text.innerText = "You picked " + guess + ". Here are the random numbers:\n"; @@ -445,22 +445,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -482,41 +482,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -525,11 +525,11 @@ const locations = [ text: "You defeat the dragon! YOU WIN THE GAME! 🎉" }, { - name: "easter egg", - "button text": ["2", "8", "Go to town square?"], - "button functions": [pickTwo, pickEight, goTown], - text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" - } + name: "easter egg", + "button text": ["2", "8", "Go to town square?"], + "button functions": [pickTwo, pickEight, goTown], + text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" + } ]; // initialize buttons @@ -537,15 +537,15 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -557,7 +557,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -572,76 +572,76 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); - if (isMonsterHit()) { - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - } else { - text.innerText += " You miss."; - } - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - fighting === 2 ? winGame() : defeatMonster(); + if (isMonsterHit()) { + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + } else { + text.innerText += " You miss."; + } + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + fighting === 2 ? winGame() : defeatMonster(); } if (Math.random() <= .1 && inventory.length !== 1) { text.innerText += " Your " + inventory.pop() + " breaks."; @@ -655,7 +655,7 @@ function getMonsterAttackValue(level) { } function isMonsterHit() { - return Math.random() > .2 || health < 20; + return Math.random() > .2 || health < 20; } function dodge() { @@ -663,10 +663,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -679,19 +679,19 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } function easterEgg() { - update(locations[7]); + update(locations[7]); } function pickTwo() { @@ -703,10 +703,10 @@ function pickEight() { } function pick(guess) { - let numbers = []; - while(numbers.length < 10) { - numbers.push(Math.floor(Math.random() * 11)); - } + let numbers = []; + while(numbers.length < 10) { + numbers.push(Math.floor(Math.random() * 11)); + } text.innerText = "You picked " + guess + ". Here are the random numbers:\n"; diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-147.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-147.md index 005b147d8b..af70e67652 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-147.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-147.md @@ -23,7 +23,7 @@ Inside the for loop, use the `+=` operator to add to the end of `text.innerText` ```yml tests: - text: See description above for instructions. - testString: assert( pick.toString().replace(/\s/g, '').includes('for(vari=0;i<10;i++){if(Date.now()-_LP2>100)break;text.innerText+=numbers[i]+"\\n";}') || pick.toString().replace(/\s/g, '').includes('for(vari=0;i<10;i++){if(Date.now()-_LP2>100)break;text.innerText+="".concat(numbers[i],"\\n");}') ); # Also test for automatic loop protection + testString: assert( pick.toString().replace(/\s/g, '').includes('text.innerText+=numbers[i]+"\\n";}}') ); # Also test for automatic loop protection ``` @@ -56,22 +56,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -93,41 +93,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -136,11 +136,11 @@ const locations = [ text: "You defeat the dragon! YOU WIN THE GAME! 🎉" }, { - name: "easter egg", - "button text": ["2", "8", "Go to town square?"], - "button functions": [pickTwo, pickEight, goTown], - text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" - } + name: "easter egg", + "button text": ["2", "8", "Go to town square?"], + "button functions": [pickTwo, pickEight, goTown], + text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" + } ]; // initialize buttons @@ -150,13 +150,13 @@ button3.onclick = fightDragon; function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -183,76 +183,76 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); - if (isMonsterHit()) { - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - } else { - text.innerText += " You miss."; - } - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - fighting === 2 ? winGame() : defeatMonster(); + if (isMonsterHit()) { + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + } else { + text.innerText += " You miss."; + } + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + fighting === 2 ? winGame() : defeatMonster(); } if (Math.random() <= .1 && inventory.length !== 1) { @@ -268,7 +268,7 @@ function getMonsterAttackValue(level) { } function isMonsterHit() { - return Math.random() > .2 || health < 20; + return Math.random() > .2 || health < 20; } function dodge() { @@ -276,10 +276,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -292,19 +292,19 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } function easterEgg() { - update(locations[7]); + update(locations[7]); } function pickTwo() { @@ -316,10 +316,10 @@ function pickEight() { } function pick(guess) { - let numbers = []; - while(numbers.length < 10) { - numbers.push(Math.floor(Math.random() * 11)); - } + let numbers = []; + while(numbers.length < 10) { + numbers.push(Math.floor(Math.random() * 11)); + } text.innerText = "You picked " + guess + ". Here are the random numbers:\n"; @@ -443,22 +443,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -480,41 +480,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -523,11 +523,11 @@ const locations = [ text: "You defeat the dragon! YOU WIN THE GAME! 🎉" }, { - name: "easter egg", - "button text": ["2", "8", "Go to town square?"], - "button functions": [pickTwo, pickEight, goTown], - text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" - } + name: "easter egg", + "button text": ["2", "8", "Go to town square?"], + "button functions": [pickTwo, pickEight, goTown], + text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" + } ]; // initialize buttons @@ -535,15 +535,15 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -555,7 +555,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -570,76 +570,76 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); - if (isMonsterHit()) { - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - } else { - text.innerText += " You miss."; - } - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - fighting === 2 ? winGame() : defeatMonster(); + if (isMonsterHit()) { + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + } else { + text.innerText += " You miss."; + } + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + fighting === 2 ? winGame() : defeatMonster(); } if (Math.random() <= .1 && inventory.length !== 1) { text.innerText += " Your " + inventory.pop() + " breaks."; @@ -653,7 +653,7 @@ function getMonsterAttackValue(level) { } function isMonsterHit() { - return Math.random() > .2 || health < 20; + return Math.random() > .2 || health < 20; } function dodge() { @@ -661,10 +661,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -677,19 +677,19 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } function easterEgg() { - update(locations[7]); + update(locations[7]); } function pickTwo() { @@ -701,10 +701,10 @@ function pickEight() { } function pick(guess) { - let numbers = []; - while(numbers.length < 10) { - numbers.push(Math.floor(Math.random() * 11)); - } + let numbers = []; + while(numbers.length < 10) { + numbers.push(Math.floor(Math.random() * 11)); + } text.innerText = "You picked " + guess + ". Here are the random numbers:\n"; diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-148.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-148.md index 1b985c0c01..3c4cd9f372 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-148.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-148.md @@ -58,22 +58,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -95,41 +95,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -138,11 +138,11 @@ const locations = [ text: "You defeat the dragon! YOU WIN THE GAME! 🎉" }, { - name: "easter egg", - "button text": ["2", "8", "Go to town square?"], - "button functions": [pickTwo, pickEight, goTown], - text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" - } + name: "easter egg", + "button text": ["2", "8", "Go to town square?"], + "button functions": [pickTwo, pickEight, goTown], + text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" + } ]; // initialize buttons @@ -152,13 +152,13 @@ button3.onclick = fightDragon; function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -185,76 +185,76 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); - if (isMonsterHit()) { - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - } else { - text.innerText += " You miss."; - } - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - fighting === 2 ? winGame() : defeatMonster(); + if (isMonsterHit()) { + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + } else { + text.innerText += " You miss."; + } + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + fighting === 2 ? winGame() : defeatMonster(); } if (Math.random() <= .1 && inventory.length !== 1) { @@ -270,7 +270,7 @@ function getMonsterAttackValue(level) { } function isMonsterHit() { - return Math.random() > .2 || health < 20; + return Math.random() > .2 || health < 20; } function dodge() { @@ -278,10 +278,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -294,19 +294,19 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } function easterEgg() { - update(locations[7]); + update(locations[7]); } function pickTwo() { @@ -318,10 +318,10 @@ function pickEight() { } function pick(guess) { - let numbers = []; - while(numbers.length < 10) { - numbers.push(Math.floor(Math.random() * 11)); - } + let numbers = []; + while(numbers.length < 10) { + numbers.push(Math.floor(Math.random() * 11)); + } text.innerText = "You picked " + guess + ". Here are the random numbers:\n"; @@ -445,22 +445,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -482,41 +482,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -525,11 +525,11 @@ const locations = [ text: "You defeat the dragon! YOU WIN THE GAME! 🎉" }, { - name: "easter egg", - "button text": ["2", "8", "Go to town square?"], - "button functions": [pickTwo, pickEight, goTown], - text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" - } + name: "easter egg", + "button text": ["2", "8", "Go to town square?"], + "button functions": [pickTwo, pickEight, goTown], + text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" + } ]; // initialize buttons @@ -537,15 +537,15 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -557,7 +557,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -572,76 +572,76 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); - if (isMonsterHit()) { - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - } else { - text.innerText += " You miss."; - } - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - fighting === 2 ? winGame() : defeatMonster(); + if (isMonsterHit()) { + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + } else { + text.innerText += " You miss."; + } + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + fighting === 2 ? winGame() : defeatMonster(); } if (Math.random() <= .1 && inventory.length !== 1) { text.innerText += " Your " + inventory.pop() + " breaks."; @@ -655,7 +655,7 @@ function getMonsterAttackValue(level) { } function isMonsterHit() { - return Math.random() > .2 || health < 20; + return Math.random() > .2 || health < 20; } function dodge() { @@ -663,10 +663,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -679,19 +679,19 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } function easterEgg() { - update(locations[7]); + update(locations[7]); } function pickTwo() { @@ -703,10 +703,10 @@ function pickEight() { } function pick(guess) { - let numbers = []; - while(numbers.length < 10) { - numbers.push(Math.floor(Math.random() * 11)); - } + let numbers = []; + while(numbers.length < 10) { + numbers.push(Math.floor(Math.random() * 11)); + } text.innerText = "You picked " + guess + ". Here are the random numbers:\n"; diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-149.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-149.md index 620fbe7262..9f1995c781 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-149.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-149.md @@ -56,22 +56,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -93,41 +93,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -136,11 +136,11 @@ const locations = [ text: "You defeat the dragon! YOU WIN THE GAME! 🎉" }, { - name: "easter egg", - "button text": ["2", "8", "Go to town square?"], - "button functions": [pickTwo, pickEight, goTown], - text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" - } + name: "easter egg", + "button text": ["2", "8", "Go to town square?"], + "button functions": [pickTwo, pickEight, goTown], + text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" + } ]; // initialize buttons @@ -150,13 +150,13 @@ button3.onclick = fightDragon; function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -183,76 +183,76 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); - if (isMonsterHit()) { - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - } else { - text.innerText += " You miss."; - } - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - fighting === 2 ? winGame() : defeatMonster(); + if (isMonsterHit()) { + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + } else { + text.innerText += " You miss."; + } + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + fighting === 2 ? winGame() : defeatMonster(); } if (Math.random() <= .1 && inventory.length !== 1) { @@ -268,7 +268,7 @@ function getMonsterAttackValue(level) { } function isMonsterHit() { - return Math.random() > .2 || health < 20; + return Math.random() > .2 || health < 20; } function dodge() { @@ -276,10 +276,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -292,19 +292,19 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } function easterEgg() { - update(locations[7]); + update(locations[7]); } function pickTwo() { @@ -316,10 +316,10 @@ function pickEight() { } function pick(guess) { - let numbers = []; - while(numbers.length < 10) { - numbers.push(Math.floor(Math.random() * 11)); - } + let numbers = []; + while(numbers.length < 10) { + numbers.push(Math.floor(Math.random() * 11)); + } text.innerText = "You picked " + guess + ". Here are the random numbers:\n"; @@ -447,22 +447,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -484,41 +484,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -527,11 +527,11 @@ const locations = [ text: "You defeat the dragon! YOU WIN THE GAME! 🎉" }, { - name: "easter egg", - "button text": ["2", "8", "Go to town square?"], - "button functions": [pickTwo, pickEight, goTown], - text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" - } + name: "easter egg", + "button text": ["2", "8", "Go to town square?"], + "button functions": [pickTwo, pickEight, goTown], + text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" + } ]; // initialize buttons @@ -539,15 +539,15 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -559,7 +559,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -574,76 +574,76 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); - if (isMonsterHit()) { - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - } else { - text.innerText += " You miss."; - } - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - fighting === 2 ? winGame() : defeatMonster(); + if (isMonsterHit()) { + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + } else { + text.innerText += " You miss."; + } + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + fighting === 2 ? winGame() : defeatMonster(); } if (Math.random() <= .1 && inventory.length !== 1) { text.innerText += " Your " + inventory.pop() + " breaks."; @@ -657,7 +657,7 @@ function getMonsterAttackValue(level) { } function isMonsterHit() { - return Math.random() > .2 || health < 20; + return Math.random() > .2 || health < 20; } function dodge() { @@ -665,10 +665,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -681,19 +681,19 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } function easterEgg() { - update(locations[7]); + update(locations[7]); } function pickTwo() { @@ -705,10 +705,10 @@ function pickEight() { } function pick(guess) { - let numbers = []; - while(numbers.length < 10) { - numbers.push(Math.floor(Math.random() * 11)); - } + let numbers = []; + while(numbers.length < 10) { + numbers.push(Math.floor(Math.random() * 11)); + } text.innerText = "You picked " + guess + ". Here are the random numbers:\n"; @@ -716,11 +716,11 @@ function pick(guess) { text.innerText += numbers[i] + "\n"; } - if (numbers.indexOf(guess) !== -1) { - text.innerText += "Right! You win 20 gold!"; - gold += 20; - goldText.innerText = gold; - } + if (numbers.indexOf(guess) !== -1) { + text.innerText += "Right! You win 20 gold!"; + gold += 20; + goldText.innerText = gold; + } } ``` diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-150.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-150.md index e3addaa879..b828fad67c 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-150.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-150.md @@ -56,22 +56,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -93,41 +93,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -136,11 +136,11 @@ const locations = [ text: "You defeat the dragon! YOU WIN THE GAME! 🎉" }, { - name: "easter egg", - "button text": ["2", "8", "Go to town square?"], - "button functions": [pickTwo, pickEight, goTown], - text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" - } + name: "easter egg", + "button text": ["2", "8", "Go to town square?"], + "button functions": [pickTwo, pickEight, goTown], + text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" + } ]; // initialize buttons @@ -150,13 +150,13 @@ button3.onclick = fightDragon; function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -183,76 +183,76 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); - if (isMonsterHit()) { - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - } else { - text.innerText += " You miss."; - } - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - fighting === 2 ? winGame() : defeatMonster(); + if (isMonsterHit()) { + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + } else { + text.innerText += " You miss."; + } + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + fighting === 2 ? winGame() : defeatMonster(); } if (Math.random() <= .1 && inventory.length !== 1) { @@ -268,7 +268,7 @@ function getMonsterAttackValue(level) { } function isMonsterHit() { - return Math.random() > .2 || health < 20; + return Math.random() > .2 || health < 20; } function dodge() { @@ -276,10 +276,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -292,19 +292,19 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } function easterEgg() { - update(locations[7]); + update(locations[7]); } function pickTwo() { @@ -316,10 +316,10 @@ function pickEight() { } function pick(guess) { - let numbers = []; - while(numbers.length < 10) { - numbers.push(Math.floor(Math.random() * 11)); - } + let numbers = []; + while(numbers.length < 10) { + numbers.push(Math.floor(Math.random() * 11)); + } text.innerText = "You picked " + guess + ". Here are the random numbers:\n"; @@ -327,11 +327,11 @@ function pick(guess) { text.innerText += numbers[i] + "\n"; } - if (numbers.indexOf(guess) !== -1) { - text.innerText += "Right! You win 20 gold!"; - gold += 20; - goldText.innerText = gold; - } + if (numbers.indexOf(guess) !== -1) { + text.innerText += "Right! You win 20 gold!"; + gold += 20; + goldText.innerText = gold; + } } @@ -449,22 +449,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -486,41 +486,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -529,11 +529,11 @@ const locations = [ text: "You defeat the dragon! YOU WIN THE GAME! 🎉" }, { - name: "easter egg", - "button text": ["2", "8", "Go to town square?"], - "button functions": [pickTwo, pickEight, goTown], - text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" - } + name: "easter egg", + "button text": ["2", "8", "Go to town square?"], + "button functions": [pickTwo, pickEight, goTown], + text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" + } ]; // initialize buttons @@ -541,15 +541,15 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -561,7 +561,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -576,76 +576,76 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); - if (isMonsterHit()) { - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - } else { - text.innerText += " You miss."; - } - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - fighting === 2 ? winGame() : defeatMonster(); + if (isMonsterHit()) { + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + } else { + text.innerText += " You miss."; + } + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + fighting === 2 ? winGame() : defeatMonster(); } if (Math.random() <= .1 && inventory.length !== 1) { text.innerText += " Your " + inventory.pop() + " breaks."; @@ -659,7 +659,7 @@ function getMonsterAttackValue(level) { } function isMonsterHit() { - return Math.random() > .2 || health < 20; + return Math.random() > .2 || health < 20; } function dodge() { @@ -667,10 +667,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -683,19 +683,19 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } function easterEgg() { - update(locations[7]); + update(locations[7]); } function pickTwo() { @@ -707,10 +707,10 @@ function pickEight() { } function pick(guess) { - let numbers = []; - while(numbers.length < 10) { - numbers.push(Math.floor(Math.random() * 11)); - } + let numbers = []; + while(numbers.length < 10) { + numbers.push(Math.floor(Math.random() * 11)); + } text.innerText = "You picked " + guess + ". Here are the random numbers:\n"; @@ -718,15 +718,15 @@ function pick(guess) { text.innerText += numbers[i] + "\n"; } - if (numbers.indexOf(guess) !== -1) { - text.innerText += "Right! You win 20 gold!"; - gold += 20; - goldText.innerText = gold; - } else { - text.innerText += "Wrong! You lose 10 health!"; - health -= 10; - healthText.innerText = health; - } + if (numbers.indexOf(guess) !== -1) { + text.innerText += "Right! You win 20 gold!"; + gold += 20; + goldText.innerText = gold; + } else { + text.innerText += "Wrong! You lose 10 health!"; + health -= 10; + healthText.innerText = health; + } } ``` diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-151.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-151.md index 966c31092b..4bf0dc2afe 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-151.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-151.md @@ -56,22 +56,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -93,41 +93,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -136,11 +136,11 @@ const locations = [ text: "You defeat the dragon! YOU WIN THE GAME! 🎉" }, { - name: "easter egg", - "button text": ["2", "8", "Go to town square?"], - "button functions": [pickTwo, pickEight, goTown], - text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" - } + name: "easter egg", + "button text": ["2", "8", "Go to town square?"], + "button functions": [pickTwo, pickEight, goTown], + text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" + } ]; // initialize buttons @@ -150,13 +150,13 @@ button3.onclick = fightDragon; function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -183,76 +183,76 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); - if (isMonsterHit()) { - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - } else { - text.innerText += " You miss."; - } - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - fighting === 2 ? winGame() : defeatMonster(); + if (isMonsterHit()) { + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + } else { + text.innerText += " You miss."; + } + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + fighting === 2 ? winGame() : defeatMonster(); } if (Math.random() <= .1 && inventory.length !== 1) { @@ -268,7 +268,7 @@ function getMonsterAttackValue(level) { } function isMonsterHit() { - return Math.random() > .2 || health < 20; + return Math.random() > .2 || health < 20; } function dodge() { @@ -276,10 +276,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -292,19 +292,19 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } function easterEgg() { - update(locations[7]); + update(locations[7]); } function pickTwo() { @@ -316,10 +316,10 @@ function pickEight() { } function pick(guess) { - let numbers = []; - while(numbers.length < 10) { - numbers.push(Math.floor(Math.random() * 11)); - } + let numbers = []; + while(numbers.length < 10) { + numbers.push(Math.floor(Math.random() * 11)); + } text.innerText = "You picked " + guess + ". Here are the random numbers:\n"; @@ -327,15 +327,15 @@ function pick(guess) { text.innerText += numbers[i] + "\n"; } - if (numbers.indexOf(guess) !== -1) { - text.innerText += "Right! You win 20 gold!"; - gold += 20; - goldText.innerText = gold; - } else { - text.innerText += "Wrong! You lose 10 health!"; - health -= 10; - healthText.innerText = health; - } + if (numbers.indexOf(guess) !== -1) { + text.innerText += "Right! You win 20 gold!"; + gold += 20; + goldText.innerText = gold; + } else { + text.innerText += "Wrong! You lose 10 health!"; + health -= 10; + healthText.innerText = health; + } } @@ -453,22 +453,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -490,41 +490,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -533,11 +533,11 @@ const locations = [ text: "You defeat the dragon! YOU WIN THE GAME! 🎉" }, { - name: "easter egg", - "button text": ["2", "8", "Go to town square?"], - "button functions": [pickTwo, pickEight, goTown], - text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" - } + name: "easter egg", + "button text": ["2", "8", "Go to town square?"], + "button functions": [pickTwo, pickEight, goTown], + text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" + } ]; // initialize buttons @@ -545,15 +545,15 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -565,7 +565,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -580,76 +580,76 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); - if (isMonsterHit()) { - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - } else { - text.innerText += " You miss."; - } - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - fighting === 2 ? winGame() : defeatMonster(); + if (isMonsterHit()) { + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + } else { + text.innerText += " You miss."; + } + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + fighting === 2 ? winGame() : defeatMonster(); } if (Math.random() <= .1 && inventory.length !== 1) { text.innerText += " Your " + inventory.pop() + " breaks."; @@ -663,7 +663,7 @@ function getMonsterAttackValue(level) { } function isMonsterHit() { - return Math.random() > .2 || health < 20; + return Math.random() > .2 || health < 20; } function dodge() { @@ -671,10 +671,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -687,19 +687,19 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } function easterEgg() { - update(locations[7]); + update(locations[7]); } function pickTwo() { @@ -711,10 +711,10 @@ function pickEight() { } function pick(guess) { - let numbers = []; - while(numbers.length < 10) { - numbers.push(Math.floor(Math.random() * 11)); - } + let numbers = []; + while(numbers.length < 10) { + numbers.push(Math.floor(Math.random() * 11)); + } text.innerText = "You picked " + guess + ". Here are the random numbers:\n"; @@ -722,18 +722,18 @@ function pick(guess) { text.innerText += numbers[i] + "\n"; } - if (numbers.indexOf(guess) !== -1) { - text.innerText += "Right! You win 20 gold!"; - gold += 20; - goldText.innerText = gold; - } else { - text.innerText += "Wrong! You lose 10 health!"; - health -= 10; + if (numbers.indexOf(guess) !== -1) { + text.innerText += "Right! You win 20 gold!"; + gold += 20; + goldText.innerText = gold; + } else { + text.innerText += "Wrong! You lose 10 health!"; + health -= 10; healthText.innerText = health; if (health <= 0) { - lose(); - } - } + lose(); + } + } } ``` diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-152.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-152.md index 0d4821b8b6..1123eafa91 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-152.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-152.md @@ -57,22 +57,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -94,41 +94,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, goTown], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, goTown], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -137,11 +137,11 @@ const locations = [ text: "You defeat the dragon! YOU WIN THE GAME! 🎉" }, { - name: "easter egg", - "button text": ["2", "8", "Go to town square?"], - "button functions": [pickTwo, pickEight, goTown], - text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" - } + name: "easter egg", + "button text": ["2", "8", "Go to town square?"], + "button functions": [pickTwo, pickEight, goTown], + text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" + } ]; // initialize buttons @@ -151,13 +151,13 @@ button3.onclick = fightDragon; function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -184,76 +184,76 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); - if (isMonsterHit()) { - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - } else { - text.innerText += " You miss."; - } - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - fighting === 2 ? winGame() : defeatMonster(); + if (isMonsterHit()) { + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + } else { + text.innerText += " You miss."; + } + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + fighting === 2 ? winGame() : defeatMonster(); } if (Math.random() <= .1 && inventory.length !== 1) { @@ -269,7 +269,7 @@ function getMonsterAttackValue(level) { } function isMonsterHit() { - return Math.random() > .2 || health < 20; + return Math.random() > .2 || health < 20; } function dodge() { @@ -277,10 +277,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -293,19 +293,19 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } function easterEgg() { - update(locations[7]); + update(locations[7]); } function pickTwo() { @@ -317,10 +317,10 @@ function pickEight() { } function pick(guess) { - let numbers = []; - while(numbers.length < 10) { - numbers.push(Math.floor(Math.random() * 11)); - } + let numbers = []; + while(numbers.length < 10) { + numbers.push(Math.floor(Math.random() * 11)); + } text.innerText = "You picked " + guess + ". Here are the random numbers:\n"; @@ -328,18 +328,18 @@ function pick(guess) { text.innerText += numbers[i] + "\n"; } - if (numbers.indexOf(guess) !== -1) { - text.innerText += "Right! You win 20 gold!"; - gold += 20; - goldText.innerText = gold; - } else { - text.innerText += "Wrong! You lose 10 health!"; - health -= 10; + if (numbers.indexOf(guess) !== -1) { + text.innerText += "Right! You win 20 gold!"; + gold += 20; + goldText.innerText = gold; + } else { + text.innerText += "Wrong! You lose 10 health!"; + health -= 10; healthText.innerText = health; if (health <= 0) { - lose(); - } - } + lose(); + } + } } @@ -457,22 +457,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -494,41 +494,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, easterEgg], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, easterEgg], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -537,11 +537,11 @@ const locations = [ text: "You defeat the dragon! YOU WIN THE GAME! 🎉" }, { - name: "easter egg", - "button text": ["2", "8", "Go to town square?"], - "button functions": [pickTwo, pickEight, goTown], - text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" - } + name: "easter egg", + "button text": ["2", "8", "Go to town square?"], + "button functions": [pickTwo, pickEight, goTown], + text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" + } ]; // initialize buttons @@ -549,15 +549,15 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -569,7 +569,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -584,76 +584,76 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); - if (isMonsterHit()) { - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - } else { - text.innerText += " You miss."; - } - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - fighting === 2 ? winGame() : defeatMonster(); + if (isMonsterHit()) { + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + } else { + text.innerText += " You miss."; + } + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + fighting === 2 ? winGame() : defeatMonster(); } if (Math.random() <= .1 && inventory.length !== 1) { text.innerText += " Your " + inventory.pop() + " breaks."; @@ -667,7 +667,7 @@ function getMonsterAttackValue(level) { } function isMonsterHit() { - return Math.random() > .2 || health < 20; + return Math.random() > .2 || health < 20; } function dodge() { @@ -675,10 +675,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -691,19 +691,19 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } function easterEgg() { - update(locations[7]); + update(locations[7]); } function pickTwo() { @@ -715,10 +715,10 @@ function pickEight() { } function pick(guess) { - let numbers = []; - while(numbers.length < 10) { - numbers.push(Math.floor(Math.random() * 11)); - } + let numbers = []; + while(numbers.length < 10) { + numbers.push(Math.floor(Math.random() * 11)); + } text.innerText = "You picked " + guess + ". Here are the random numbers:\n"; @@ -726,18 +726,18 @@ function pick(guess) { text.innerText += numbers[i] + "\n"; } - if (numbers.indexOf(guess) !== -1) { - text.innerText += "Right! You win 20 gold!"; - gold += 20; - goldText.innerText = gold; - } else { - text.innerText += "Wrong! You lose 10 health!"; - health -= 10; + if (numbers.indexOf(guess) !== -1) { + text.innerText += "Right! You win 20 gold!"; + gold += 20; + goldText.innerText = gold; + } else { + text.innerText += "Wrong! You lose 10 health!"; + health -= 10; healthText.innerText = health; if (health <= 0) { - lose(); - } - } + lose(); + } + } } ``` diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-153.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-153.md index 92fba2b846..1dbba1d2f5 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-153.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-153.md @@ -56,22 +56,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -93,41 +93,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, easterEgg], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, easterEgg], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -136,11 +136,11 @@ const locations = [ text: "You defeat the dragon! YOU WIN THE GAME! 🎉" }, { - name: "easter egg", - "button text": ["2", "8", "Go to town square?"], - "button functions": [pickTwo, pickEight, goTown], - text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" - } + name: "easter egg", + "button text": ["2", "8", "Go to town square?"], + "button functions": [pickTwo, pickEight, goTown], + text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" + } ]; // initialize buttons @@ -150,13 +150,13 @@ button3.onclick = fightDragon; function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -183,76 +183,76 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); - if (isMonsterHit()) { - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - } else { - text.innerText += " You miss."; - } - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - fighting === 2 ? winGame() : defeatMonster(); + if (isMonsterHit()) { + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + } else { + text.innerText += " You miss."; + } + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + fighting === 2 ? winGame() : defeatMonster(); } if (Math.random() <= .1 && inventory.length !== 1) { @@ -268,7 +268,7 @@ function getMonsterAttackValue(level) { } function isMonsterHit() { - return Math.random() > .2 || health < 20; + return Math.random() > .2 || health < 20; } function dodge() { @@ -276,10 +276,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -292,19 +292,19 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } function easterEgg() { - update(locations[7]); + update(locations[7]); } function pickTwo() { @@ -316,10 +316,10 @@ function pickEight() { } function pick(guess) { - let numbers = []; - while(numbers.length < 10) { - numbers.push(Math.floor(Math.random() * 11)); - } + let numbers = []; + while(numbers.length < 10) { + numbers.push(Math.floor(Math.random() * 11)); + } text.innerText = "You picked " + guess + ". Here are the random numbers:\n"; @@ -327,18 +327,18 @@ function pick(guess) { text.innerText += numbers[i] + "\n"; } - if (numbers.indexOf(guess) !== -1) { - text.innerText += "Right! You win 20 gold!"; - gold += 20; - goldText.innerText = gold; - } else { - text.innerText += "Wrong! You lose 10 health!"; - health -= 10; + if (numbers.indexOf(guess) !== -1) { + text.innerText += "Right! You win 20 gold!"; + gold += 20; + goldText.innerText = gold; + } else { + text.innerText += "Wrong! You lose 10 health!"; + health -= 10; healthText.innerText = health; if (health <= 0) { - lose(); - } - } + lose(); + } + } } @@ -456,22 +456,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -493,41 +493,41 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - }, { - name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], - "button functions": [goTown, goTown, easterEgg], - text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' - }, + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, { - name: "lose", - "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], - "button functions": [restart, restart, restart], - text: "You die. ☠️" + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + }, + { + name: "kill monster", + "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button functions": [goTown, goTown, easterEgg], + text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' + }, + { + name: "lose", + "button text": ["REPLAY?", "REPLAY?", "REPLAY?"], + "button functions": [restart, restart, restart], + text: "You die. ☠️" }, { name: "win", @@ -536,11 +536,11 @@ const locations = [ text: "You defeat the dragon! YOU WIN THE GAME! 🎉" }, { - name: "easter egg", - "button text": ["2", "8", "Go to town square?"], - "button functions": [pickTwo, pickEight, goTown], - text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" - } + name: "easter egg", + "button text": ["2", "8", "Go to town square?"], + "button functions": [pickTwo, pickEight, goTown], + text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" + } ]; // initialize buttons @@ -548,15 +548,15 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { monsterStats.style.display = "none"; - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -568,7 +568,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -583,76 +583,76 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= getMonsterAttackValue(monsters[fighting].level); + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= getMonsterAttackValue(monsters[fighting].level); - if (isMonsterHit()) { - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; - } else { - text.innerText += " You miss."; - } - healthText.innerText = health; - monsterHealthText.innerText = monsterHealth; - if (health <= 0) { - lose(); - } else if (monsterHealth <= 0) { - fighting === 2 ? winGame() : defeatMonster(); + if (isMonsterHit()) { + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + } else { + text.innerText += " You miss."; + } + healthText.innerText = health; + monsterHealthText.innerText = monsterHealth; + if (health <= 0) { + lose(); + } else if (monsterHealth <= 0) { + fighting === 2 ? winGame() : defeatMonster(); } if (Math.random() <= .1 && inventory.length !== 1) { text.innerText += " Your " + inventory.pop() + " breaks."; @@ -666,7 +666,7 @@ function getMonsterAttackValue(level) { } function isMonsterHit() { - return Math.random() > .2 || health < 20; + return Math.random() > .2 || health < 20; } function dodge() { @@ -674,10 +674,10 @@ function dodge() { } function defeatMonster() { - gold += Math.floor(monsters[fighting].level * 6.7); - xp += monsters[fighting].level; - goldText.innerText = gold; - xpText.innerText = xp; + gold += Math.floor(monsters[fighting].level * 6.7); + xp += monsters[fighting].level; + goldText.innerText = gold; + xpText.innerText = xp; update(locations[4]); } @@ -690,19 +690,19 @@ function winGame() { } function restart() { - xp = 0; - health = 100; - gold = 50; - currentWeapon = 0; - inventory = ["stick"]; - goldText.innerText = gold; - healthText.innerText = health; - xpText.innerText = xp; - goTown(); + xp = 0; + health = 100; + gold = 50; + currentWeapon = 0; + inventory = ["stick"]; + goldText.innerText = gold; + healthText.innerText = health; + xpText.innerText = xp; + goTown(); } function easterEgg() { - update(locations[7]); + update(locations[7]); } function pickTwo() { @@ -714,10 +714,10 @@ function pickEight() { } function pick(guess) { - let numbers = []; - while(numbers.length < 10) { - numbers.push(Math.floor(Math.random() * 11)); - } + let numbers = []; + while(numbers.length < 10) { + numbers.push(Math.floor(Math.random() * 11)); + } text.innerText = "You picked " + guess + ". Here are the random numbers:\n"; @@ -725,18 +725,18 @@ function pick(guess) { text.innerText += numbers[i] + "\n"; } - if (numbers.indexOf(guess) !== -1) { - text.innerText += "Right! You win 20 gold!"; - gold += 20; - goldText.innerText = gold; - } else { - text.innerText += "Wrong! You lose 10 health!"; - health -= 10; + if (numbers.indexOf(guess) !== -1) { + text.innerText += "Right! You win 20 gold!"; + gold += 20; + goldText.innerText = gold; + } else { + text.innerText += "Wrong! You lose 10 health!"; + health -= 10; healthText.innerText = health; if (health <= 0) { - lose(); - } - } + lose(); + } + } } ``` diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-17.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-17.md index b10cdbefd3..5373cb6a8b 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-17.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-17.md @@ -12,7 +12,7 @@ For now, make the `goStore` function output the message "Going to store." to the ```js function functionName() { - console.log("Hello World"); + console.log("Hello World"); } ``` diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-18.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-18.md index 8ceb6226ee..02f1b420c7 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-18.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-18.md @@ -188,7 +188,7 @@ function goStore() { } function goCave() { - console.log("Going to cave."); + console.log("Going to cave."); } ``` diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-19.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-19.md index 1480613eb1..5039cb8e00 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-19.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-19.md @@ -194,7 +194,7 @@ function goStore() { } function goCave() { - console.log("Going to cave."); + console.log("Going to cave."); } function fightDragon() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-20.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-20.md index ae8aed6542..897a54e4bf 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-20.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-20.md @@ -196,11 +196,11 @@ button2.onclick = goCave; button3.onclick = fightDragon; function goStore() { - button1.innerText = "Buy 10 health (10 gold)"; + button1.innerText = "Buy 10 health (10 gold)"; } function goCave() { - console.log("Going to cave."); + console.log("Going to cave."); } function fightDragon() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-21.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-21.md index 2d418592d5..e3802643b0 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-21.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-21.md @@ -195,11 +195,11 @@ button3.onclick = fightDragon; function goStore() { button1.innerText = "Buy 10 health (10 gold)"; button2.innerText = "Buy weapon (30 gold)"; - button3.innerText = "Go to town square"; + button3.innerText = "Go to town square"; } function goCave() { - console.log("Going to cave."); + console.log("Going to cave."); } function fightDragon() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-22.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-22.md index c97c5e3632..c81a24949b 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-22.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-22.md @@ -198,12 +198,12 @@ function goStore() { button2.innerText = "Buy weapon (30 gold)"; button3.innerText = "Go to town square"; button1.onclick = buyHealth; - button2.onclick = buyWeapon; - button3.onclick = goTown; + button2.onclick = buyWeapon; + button3.onclick = goTown; } function goCave() { - console.log("Going to cave."); + console.log("Going to cave."); } function fightDragon() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-23.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-23.md index 244120e744..3cb9859259 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-23.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-23.md @@ -201,13 +201,13 @@ function goStore() { button2.innerText = "Buy weapon (30 gold)"; button3.innerText = "Go to town square"; button1.onclick = buyHealth; - button2.onclick = buyWeapon; + button2.onclick = buyWeapon; button3.onclick = goTown; text.innerText = "You enter the store."; } function goCave() { - console.log("Going to cave."); + console.log("Going to cave."); } function fightDragon() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-24.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-24.md index 092b34aaaf..14ea7bf540 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-24.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-24.md @@ -202,13 +202,13 @@ function goStore() { button2.innerText = "Buy weapon (30 gold)"; button3.innerText = "Go to town square"; button1.onclick = buyHealth; - button2.onclick = buyWeapon; + button2.onclick = buyWeapon; button3.onclick = goTown; text.innerText = "You enter the store."; } function goCave() { - console.log("Going to cave."); + console.log("Going to cave."); } function fightDragon() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-25.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-25.md index 82e886db28..b64b73a7bf 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-25.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-25.md @@ -222,13 +222,13 @@ function goStore() { button2.innerText = "Buy weapon (30 gold)"; button3.innerText = "Go to town square"; button1.onclick = buyHealth; - button2.onclick = buyWeapon; + button2.onclick = buyWeapon; button3.onclick = goTown; text.innerText = "You enter the store."; } function goCave() { - console.log("Going to cave."); + console.log("Going to cave."); } function fightDragon() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-26.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-26.md index 7715e8c213..437426150d 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-26.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-26.md @@ -214,13 +214,13 @@ button2.onclick = goCave; button3.onclick = fightDragon; function goTown() { - button1.innerText = "Go to store"; - button2.innerText = "Go to cave"; - button3.innerText = "Fight dragon"; - button1.onclick = goStore; - button2.onclick = goCave; - button3.onclick = fightDragon; - text.innerText = "You are in the town square. You see a sign that says \"Store\"."; + button1.innerText = "Go to store"; + button2.innerText = "Go to cave"; + button3.innerText = "Fight dragon"; + button1.onclick = goStore; + button2.onclick = goCave; + button3.onclick = fightDragon; + text.innerText = "You are in the town square. You see a sign that says \"Store\"."; } function goStore() { @@ -228,13 +228,13 @@ function goStore() { button2.innerText = "Buy weapon (30 gold)"; button3.innerText = "Go to town square"; button1.onclick = buyHealth; - button2.onclick = buyWeapon; + button2.onclick = buyWeapon; button3.onclick = goTown; text.innerText = "You enter the store."; } function goCave() { - console.log("Going to cave."); + console.log("Going to cave."); } function fightDragon() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-27.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-27.md index 01b7462561..1fa98e1033 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-27.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-27.md @@ -223,17 +223,17 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { } function goTown() { - button1.innerText = "Go to store"; - button2.innerText = "Go to cave"; - button3.innerText = "Fight dragon"; - button1.onclick = goStore; - button2.onclick = goCave; - button3.onclick = fightDragon; - text.innerText = "You are in the town square. You see a sign that says \"Store\"."; + button1.innerText = "Go to store"; + button2.innerText = "Go to cave"; + button3.innerText = "Fight dragon"; + button1.onclick = goStore; + button2.onclick = goCave; + button3.onclick = fightDragon; + text.innerText = "You are in the town square. You see a sign that says \"Store\"."; } function goStore() { @@ -241,13 +241,13 @@ function goStore() { button2.innerText = "Buy weapon (30 gold)"; button3.innerText = "Go to town square"; button1.onclick = buyHealth; - button2.onclick = buyWeapon; + button2.onclick = buyWeapon; button3.onclick = goTown; text.innerText = "You enter the store."; } function goCave() { - console.log("Going to cave."); + console.log("Going to cave."); } function fightDragon() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-28.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-28.md index 0925cf27c0..f4803730a5 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-28.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-28.md @@ -60,7 +60,7 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { } function goTown() { @@ -218,17 +218,17 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { } function goTown() { - button1.innerText = "Go to store"; - button2.innerText = "Go to cave"; - button3.innerText = "Fight dragon"; - button1.onclick = goStore; - button2.onclick = goCave; - button3.onclick = fightDragon; - text.innerText = "You are in the town square. You see a sign that says \"Store\"."; + button1.innerText = "Go to store"; + button2.innerText = "Go to cave"; + button3.innerText = "Fight dragon"; + button1.onclick = goStore; + button2.onclick = goCave; + button3.onclick = fightDragon; + text.innerText = "You are in the town square. You see a sign that says \"Store\"."; } function goStore() { @@ -236,13 +236,13 @@ function goStore() { button2.innerText = "Buy weapon (30 gold)"; button3.innerText = "Go to town square"; button1.onclick = buyHealth; - button2.onclick = buyWeapon; + button2.onclick = buyWeapon; button3.onclick = goTown; text.innerText = "You enter the store."; } function goCave() { - console.log("Going to cave."); + console.log("Going to cave."); } function fightDragon() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-29.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-29.md index 1ca7a0f589..f62e33af2a 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-29.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-29.md @@ -66,7 +66,7 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { } function goTown() { @@ -224,17 +224,17 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { } function goTown() { - button1.innerText = "Go to store"; - button2.innerText = "Go to cave"; - button3.innerText = "Fight dragon"; - button1.onclick = goStore; - button2.onclick = goCave; - button3.onclick = fightDragon; - text.innerText = "You are in the town square. You see a sign that says \"Store\"."; + button1.innerText = "Go to store"; + button2.innerText = "Go to cave"; + button3.innerText = "Fight dragon"; + button1.onclick = goStore; + button2.onclick = goCave; + button3.onclick = fightDragon; + text.innerText = "You are in the town square. You see a sign that says \"Store\"."; } function goStore() { @@ -242,13 +242,13 @@ function goStore() { button2.innerText = "Buy weapon (30 gold)"; button3.innerText = "Go to town square"; button1.onclick = buyHealth; - button2.onclick = buyWeapon; + button2.onclick = buyWeapon; button3.onclick = goTown; text.innerText = "You enter the store."; } function goCave() { - console.log("Going to cave."); + console.log("Going to cave."); } function fightDragon() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-30.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-30.md index 43a12cab40..039de43fb4 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-30.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-30.md @@ -14,9 +14,9 @@ For example, here is an example of an array with an object inside that has a pro ```js const arr = [ - { - name: "Quincy Larson" - } + { + name: "Quincy Larson" + } ] ``` @@ -72,7 +72,7 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { } function goTown() { @@ -224,9 +224,9 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const locations = [ - { - name: "town square" - } + { + name: "town square" + } ]; // initialize buttons @@ -234,17 +234,17 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { } function goTown() { - button1.innerText = "Go to store"; - button2.innerText = "Go to cave"; - button3.innerText = "Fight dragon"; - button1.onclick = goStore; - button2.onclick = goCave; - button3.onclick = fightDragon; - text.innerText = "You are in the town square. You see a sign that says \"Store\"."; + button1.innerText = "Go to store"; + button2.innerText = "Go to cave"; + button3.innerText = "Fight dragon"; + button1.onclick = goStore; + button2.onclick = goCave; + button3.onclick = fightDragon; + text.innerText = "You are in the town square. You see a sign that says \"Store\"."; } function goStore() { @@ -252,13 +252,13 @@ function goStore() { button2.innerText = "Buy weapon (30 gold)"; button3.innerText = "Go to town square"; button1.onclick = buyHealth; - button2.onclick = buyWeapon; + button2.onclick = buyWeapon; button3.onclick = goTown; text.innerText = "You enter the store."; } function goCave() { - console.log("Going to cave."); + console.log("Going to cave."); } function fightDragon() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-31.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-31.md index 4f1bc9ce76..55fd004102 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-31.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-31.md @@ -14,10 +14,10 @@ Here is an example: ```js const arr = [ - { - name: "Quincy Larson", - "favorite colors": [] - } + { + name: "Quincy Larson", + "favorite colors": [] + } ] ``` @@ -67,9 +67,9 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const locations = [ - { - name: "town square" - } + { + name: "town square" + } ]; // initialize buttons @@ -77,7 +77,7 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { } function goTown() { @@ -229,10 +229,10 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const locations = [ - { - name: "town square", - "button text": [] - } + { + name: "town square", + "button text": [] + } ]; // initialize buttons @@ -240,17 +240,17 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { } function goTown() { - button1.innerText = "Go to store"; - button2.innerText = "Go to cave"; - button3.innerText = "Fight dragon"; - button1.onclick = goStore; - button2.onclick = goCave; - button3.onclick = fightDragon; - text.innerText = "You are in the town square. You see a sign that says \"Store\"."; + button1.innerText = "Go to store"; + button2.innerText = "Go to cave"; + button3.innerText = "Fight dragon"; + button1.onclick = goStore; + button2.onclick = goCave; + button3.onclick = fightDragon; + text.innerText = "You are in the town square. You see a sign that says \"Store\"."; } function goStore() { @@ -258,13 +258,13 @@ function goStore() { button2.innerText = "Buy weapon (30 gold)"; button3.innerText = "Go to town square"; button1.onclick = buyHealth; - button2.onclick = buyWeapon; + button2.onclick = buyWeapon; button3.onclick = goTown; text.innerText = "You enter the store."; } function goCave() { - console.log("Going to cave."); + console.log("Going to cave."); } function fightDragon() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-32.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-32.md index e287dbfb27..c49e4b2217 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-32.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-32.md @@ -58,10 +58,10 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const locations = [ - { - name: "town square", - "button text": [] - } + { + name: "town square", + "button text": [] + } ]; // initialize buttons @@ -69,7 +69,7 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { } function goTown() { @@ -221,10 +221,10 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"] - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"] + } ]; // initialize buttons @@ -232,17 +232,17 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { } function goTown() { - button1.innerText = "Go to store"; - button2.innerText = "Go to cave"; - button3.innerText = "Fight dragon"; - button1.onclick = goStore; - button2.onclick = goCave; - button3.onclick = fightDragon; - text.innerText = "You are in the town square. You see a sign that says \"Store\"."; + button1.innerText = "Go to store"; + button2.innerText = "Go to cave"; + button3.innerText = "Fight dragon"; + button1.onclick = goStore; + button2.onclick = goCave; + button3.onclick = fightDragon; + text.innerText = "You are in the town square. You see a sign that says \"Store\"."; } function goStore() { @@ -250,13 +250,13 @@ function goStore() { button2.innerText = "Buy weapon (30 gold)"; button3.innerText = "Go to town square"; button1.onclick = buyHealth; - button2.onclick = buyWeapon; + button2.onclick = buyWeapon; button3.onclick = goTown; text.innerText = "You enter the store."; } function goCave() { - console.log("Going to cave."); + console.log("Going to cave."); } function fightDragon() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-33.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-33.md index 2a1c233f2c..eb19684216 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-33.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-33.md @@ -56,10 +56,10 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"] - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"] + } ]; // initialize buttons @@ -67,7 +67,7 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { } function goTown() { @@ -219,11 +219,11 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon] - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon] + } ]; // initialize buttons @@ -231,17 +231,17 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { } function goTown() { - button1.innerText = "Go to store"; - button2.innerText = "Go to cave"; - button3.innerText = "Fight dragon"; - button1.onclick = goStore; - button2.onclick = goCave; - button3.onclick = fightDragon; - text.innerText = "You are in the town square. You see a sign that says \"Store\"."; + button1.innerText = "Go to store"; + button2.innerText = "Go to cave"; + button3.innerText = "Fight dragon"; + button1.onclick = goStore; + button2.onclick = goCave; + button3.onclick = fightDragon; + text.innerText = "You are in the town square. You see a sign that says \"Store\"."; } function goStore() { @@ -249,13 +249,13 @@ function goStore() { button2.innerText = "Buy weapon (30 gold)"; button3.innerText = "Go to town square"; button1.onclick = buyHealth; - button2.onclick = buyWeapon; + button2.onclick = buyWeapon; button3.onclick = goTown; text.innerText = "You enter the store."; } function goCave() { - console.log("Going to cave."); + console.log("Going to cave."); } function fightDragon() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-34.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-34.md index 13501ba9fa..863437df5c 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-34.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-34.md @@ -56,11 +56,11 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon] - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon] + } ]; // initialize buttons @@ -68,7 +68,7 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { } function goTown() { @@ -220,12 +220,12 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + } ]; // initialize buttons @@ -233,17 +233,17 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { } function goTown() { - button1.innerText = "Go to store"; - button2.innerText = "Go to cave"; - button3.innerText = "Fight dragon"; - button1.onclick = goStore; - button2.onclick = goCave; - button3.onclick = fightDragon; - text.innerText = "You are in the town square. You see a sign that says \"Store\"."; + button1.innerText = "Go to store"; + button2.innerText = "Go to cave"; + button3.innerText = "Fight dragon"; + button1.onclick = goStore; + button2.onclick = goCave; + button3.onclick = fightDragon; + text.innerText = "You are in the town square. You see a sign that says \"Store\"."; } function goStore() { @@ -251,13 +251,13 @@ function goStore() { button2.innerText = "Buy weapon (30 gold)"; button3.innerText = "Go to town square"; button1.onclick = buyHealth; - button2.onclick = buyWeapon; + button2.onclick = buyWeapon; button3.onclick = goTown; text.innerText = "You enter the store."; } function goCave() { - console.log("Going to cave."); + console.log("Going to cave."); } function fightDragon() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-35.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-35.md index 925c8c6685..f73f5ea916 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-35.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-35.md @@ -57,12 +57,12 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + } ]; // initialize buttons @@ -70,7 +70,7 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { } function goTown() { @@ -222,18 +222,18 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + } ]; // initialize buttons @@ -241,17 +241,17 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { } function goTown() { - button1.innerText = "Go to store"; - button2.innerText = "Go to cave"; - button3.innerText = "Fight dragon"; - button1.onclick = goStore; - button2.onclick = goCave; - button3.onclick = fightDragon; - text.innerText = "You are in the town square. You see a sign that says \"Store\"."; + button1.innerText = "Go to store"; + button2.innerText = "Go to cave"; + button3.innerText = "Fight dragon"; + button1.onclick = goStore; + button2.onclick = goCave; + button3.onclick = fightDragon; + text.innerText = "You are in the town square. You see a sign that says \"Store\"."; } function goStore() { @@ -259,13 +259,13 @@ function goStore() { button2.innerText = "Buy weapon (30 gold)"; button3.innerText = "Go to town square"; button1.onclick = buyHealth; - button2.onclick = buyWeapon; + button2.onclick = buyWeapon; button3.onclick = goTown; text.innerText = "You enter the store."; } function goCave() { - console.log("Going to cave."); + console.log("Going to cave."); } function fightDragon() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-36.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-36.md index 695c354caa..77a001d70b 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-36.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-36.md @@ -57,18 +57,18 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + } ]; // initialize buttons @@ -76,7 +76,7 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { +function update(location) { } function goTown() { @@ -228,18 +228,18 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + } ]; // initialize buttons @@ -247,14 +247,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = "Go to store"; - button2.innerText = "Go to cave"; - button3.innerText = "Fight dragon"; - button1.onclick = goStore; - button2.onclick = goCave; - button3.onclick = fightDragon; - text.innerText = "You are in the town square. You see a sign that says \"Store\"."; +function update(location) { + button1.innerText = "Go to store"; + button2.innerText = "Go to cave"; + button3.innerText = "Fight dragon"; + button1.onclick = goStore; + button2.onclick = goCave; + button3.onclick = fightDragon; + text.innerText = "You are in the town square. You see a sign that says \"Store\"."; } function goTown() { @@ -264,11 +264,11 @@ function goStore() { } function goCave() { - console.log("Going to cave."); + console.log("Going to cave."); } function fightDragon() { - console.log("Fighting dragon."); + console.log("Fighting dragon."); } function buyHealth() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-37.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-37.md index ca5531fa97..f2e0f6f0b7 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-37.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-37.md @@ -58,18 +58,18 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + } ]; // initialize buttons @@ -77,14 +77,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = "Go to store"; - button2.innerText = "Go to cave"; - button3.innerText = "Fight dragon"; - button1.onclick = goStore; - button2.onclick = goCave; - button3.onclick = fightDragon; - text.innerText = "You are in the town square. You see a sign that says \"Store\"."; +function update(location) { + button1.innerText = "Go to store"; + button2.innerText = "Go to cave"; + button3.innerText = "Fight dragon"; + button1.onclick = goStore; + button2.onclick = goCave; + button3.onclick = fightDragon; + text.innerText = "You are in the town square. You see a sign that says \"Store\"."; } function goTown() { @@ -222,18 +222,18 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + } ]; // initialize buttons @@ -241,14 +241,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = "Go to store"; - button2.innerText = "Go to cave"; - button3.innerText = "Fight dragon"; - button1.onclick = goStore; - button2.onclick = goCave; - button3.onclick = fightDragon; - text.innerText = "You are in the town square. You see a sign that says \"Store\"."; +function update(location) { + button1.innerText = "Go to store"; + button2.innerText = "Go to cave"; + button3.innerText = "Fight dragon"; + button1.onclick = goStore; + button2.onclick = goCave; + button3.onclick = fightDragon; + text.innerText = "You are in the town square. You see a sign that says \"Store\"."; } function goTown() { @@ -259,11 +259,11 @@ function goStore() { } function goCave() { - console.log("Going to cave."); + console.log("Going to cave."); } function fightDragon() { - console.log("Fighting dragon."); + console.log("Fighting dragon."); } function buyHealth() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-38.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-38.md index bd07607d44..fa6e71955d 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-38.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-38.md @@ -58,18 +58,18 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + } ]; // initialize buttons @@ -77,14 +77,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = "Go to store"; - button2.innerText = "Go to cave"; - button3.innerText = "Fight dragon"; - button1.onclick = goStore; - button2.onclick = goCave; - button3.onclick = fightDragon; - text.innerText = "You are in the town square. You see a sign that says \"Store\"."; +function update(location) { + button1.innerText = "Go to store"; + button2.innerText = "Go to cave"; + button3.innerText = "Fight dragon"; + button1.onclick = goStore; + button2.onclick = goCave; + button3.onclick = fightDragon; + text.innerText = "You are in the town square. You see a sign that says \"Store\"."; } function goTown() { @@ -223,18 +223,18 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + } ]; // initialize buttons @@ -242,14 +242,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = "Go to store"; - button2.innerText = "Go to cave"; - button3.innerText = "Fight dragon"; - button1.onclick = goStore; - button2.onclick = goCave; - button3.onclick = fightDragon; - text.innerText = "You are in the town square. You see a sign that says \"Store\"."; +function update(location) { + button1.innerText = "Go to store"; + button2.innerText = "Go to cave"; + button3.innerText = "Fight dragon"; + button1.onclick = goStore; + button2.onclick = goCave; + button3.onclick = fightDragon; + text.innerText = "You are in the town square. You see a sign that says \"Store\"."; } function goTown() { @@ -260,11 +260,11 @@ function goStore() { } function goCave() { - console.log("Going to cave."); + console.log("Going to cave."); } function fightDragon() { - console.log("Fighting dragon."); + console.log("Fighting dragon."); } function buyHealth() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-39.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-39.md index bc617e6271..0c967fb984 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-39.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-39.md @@ -56,18 +56,18 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + } ]; // initialize buttons @@ -75,14 +75,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = "Go to store"; - button2.innerText = "Go to cave"; - button3.innerText = "Fight dragon"; - button1.onclick = goStore; - button2.onclick = goCave; - button3.onclick = fightDragon; - text.innerText = "You are in the town square. You see a sign that says \"Store\"."; +function update(location) { + button1.innerText = "Go to store"; + button2.innerText = "Go to cave"; + button3.innerText = "Fight dragon"; + button1.onclick = goStore; + button2.onclick = goCave; + button3.onclick = fightDragon; + text.innerText = "You are in the town square. You see a sign that says \"Store\"."; } function goTown() { @@ -221,18 +221,18 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + } ]; // initialize buttons @@ -240,14 +240,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = "Go to store"; - button2.innerText = "Go to cave"; - button3.innerText = "Fight dragon"; - button1.onclick = goStore; - button2.onclick = goCave; - button3.onclick = fightDragon; - text.innerText = "You are in the town square. You see a sign that says \"Store\"."; +function update(location) { + button1.innerText = "Go to store"; + button2.innerText = "Go to cave"; + button3.innerText = "Fight dragon"; + button1.onclick = goStore; + button2.onclick = goCave; + button3.onclick = fightDragon; + text.innerText = "You are in the town square. You see a sign that says \"Store\"."; } function goTown() { @@ -258,11 +258,11 @@ function goStore() { } function goCave() { - console.log("Going to cave."); + console.log("Going to cave."); } function fightDragon() { - console.log("Fighting dragon."); + console.log("Fighting dragon."); } function buyHealth() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-40.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-40.md index f0a42a957b..37bba7fcf4 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-40.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-40.md @@ -58,18 +58,18 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + } ]; // initialize buttons @@ -77,14 +77,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = "Go to store"; - button2.innerText = "Go to cave"; - button3.innerText = "Fight dragon"; - button1.onclick = goStore; - button2.onclick = goCave; - button3.onclick = fightDragon; - text.innerText = "You are in the town square. You see a sign that says \"Store\"."; +function update(location) { + button1.innerText = "Go to store"; + button2.innerText = "Go to cave"; + button3.innerText = "Fight dragon"; + button1.onclick = goStore; + button2.onclick = goCave; + button3.onclick = fightDragon; + text.innerText = "You are in the town square. You see a sign that says \"Store\"."; } function goTown() { @@ -223,18 +223,18 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + } ]; // initialize buttons @@ -242,14 +242,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"]; - button2.innerText = "Go to cave"; - button3.innerText = "Fight dragon"; - button1.onclick = goStore; - button2.onclick = goCave; - button3.onclick = fightDragon; - text.innerText = "You are in the town square. You see a sign that says \"Store\"."; +function update(location) { + button1.innerText = location["button text"]; + button2.innerText = "Go to cave"; + button3.innerText = "Fight dragon"; + button1.onclick = goStore; + button2.onclick = goCave; + button3.onclick = fightDragon; + text.innerText = "You are in the town square. You see a sign that says \"Store\"."; } function goTown() { @@ -260,11 +260,11 @@ function goStore() { } function goCave() { - console.log("Going to cave."); + console.log("Going to cave."); } function fightDragon() { - console.log("Fighting dragon."); + console.log("Fighting dragon."); } function buyHealth() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-41.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-41.md index 61c322d210..fa2dc18609 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-41.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-41.md @@ -56,18 +56,18 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + } ]; // initialize buttons @@ -75,14 +75,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"]; - button2.innerText = "Go to cave"; - button3.innerText = "Fight dragon"; - button1.onclick = goStore; - button2.onclick = goCave; - button3.onclick = fightDragon; - text.innerText = "You are in the town square. You see a sign that says \"Store\"."; +function update(location) { + button1.innerText = location["button text"]; + button2.innerText = "Go to cave"; + button3.innerText = "Fight dragon"; + button1.onclick = goStore; + button2.onclick = goCave; + button3.onclick = fightDragon; + text.innerText = "You are in the town square. You see a sign that says \"Store\"."; } function goTown() { @@ -221,18 +221,18 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + } ]; // initialize buttons @@ -240,14 +240,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = "Go to cave"; - button3.innerText = "Fight dragon"; - button1.onclick = goStore; - button2.onclick = goCave; - button3.onclick = fightDragon; - text.innerText = "You are in the town square. You see a sign that says \"Store\"."; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = "Go to cave"; + button3.innerText = "Fight dragon"; + button1.onclick = goStore; + button2.onclick = goCave; + button3.onclick = fightDragon; + text.innerText = "You are in the town square. You see a sign that says \"Store\"."; } function goTown() { @@ -258,11 +258,11 @@ function goStore() { } function goCave() { - console.log("Going to cave."); + console.log("Going to cave."); } function fightDragon() { - console.log("Fighting dragon."); + console.log("Fighting dragon."); } function buyHealth() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-42.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-42.md index 45dfb0e625..ef41733901 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-42.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-42.md @@ -56,18 +56,18 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + } ]; // initialize buttons @@ -75,14 +75,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = "Go to cave"; - button3.innerText = "Fight dragon"; - button1.onclick = goStore; - button2.onclick = goCave; - button3.onclick = fightDragon; - text.innerText = "You are in the town square. You see a sign that says \"Store\"."; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = "Go to cave"; + button3.innerText = "Fight dragon"; + button1.onclick = goStore; + button2.onclick = goCave; + button3.onclick = fightDragon; + text.innerText = "You are in the town square. You see a sign that says \"Store\"."; } function goTown() { @@ -221,18 +221,18 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + } ]; // initialize buttons @@ -240,14 +240,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = goStore; - button2.onclick = goCave; - button3.onclick = fightDragon; - text.innerText = "You are in the town square. You see a sign that says \"Store\"."; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = goStore; + button2.onclick = goCave; + button3.onclick = fightDragon; + text.innerText = "You are in the town square. You see a sign that says \"Store\"."; } function goTown() { @@ -258,11 +258,11 @@ function goStore() { } function goCave() { - console.log("Going to cave."); + console.log("Going to cave."); } function fightDragon() { - console.log("Fighting dragon."); + console.log("Fighting dragon."); } function buyHealth() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-43.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-43.md index 2013f02577..5c24b64a41 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-43.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-43.md @@ -56,18 +56,18 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + } ]; // initialize buttons @@ -75,14 +75,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = goStore; - button2.onclick = goCave; - button3.onclick = fightDragon; - text.innerText = "You are in the town square. You see a sign that says \"Store\"."; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = goStore; + button2.onclick = goCave; + button3.onclick = fightDragon; + text.innerText = "You are in the town square. You see a sign that says \"Store\"."; } function goTown() { @@ -221,18 +221,18 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + } ]; // initialize buttons @@ -240,14 +240,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = "You are in the town square. You see a sign that says \"Store\"."; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = "You are in the town square. You see a sign that says \"Store\"."; } function goTown() { @@ -258,11 +258,11 @@ function goStore() { } function goCave() { - console.log("Going to cave."); + console.log("Going to cave."); } function fightDragon() { - console.log("Fighting dragon."); + console.log("Fighting dragon."); } function buyHealth() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-44.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-44.md index 393a32cb4b..91ecff603c 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-44.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-44.md @@ -58,18 +58,18 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + } ]; // initialize buttons @@ -77,14 +77,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = "You are in the town square. You see a sign that says \"Store\"."; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = "You are in the town square. You see a sign that says \"Store\"."; } function goTown() { @@ -223,18 +223,18 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + } ]; // initialize buttons @@ -242,14 +242,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -260,11 +260,11 @@ function goStore() { } function goCave() { - console.log("Going to cave."); + console.log("Going to cave."); } function fightDragon() { - console.log("Fighting dragon."); + console.log("Fighting dragon."); } function buyHealth() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-45.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-45.md index 8c4b467910..f25299618f 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-45.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-45.md @@ -56,18 +56,18 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + } ]; // initialize buttons @@ -75,14 +75,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -221,18 +221,18 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + } ]; // initialize buttons @@ -240,14 +240,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -259,11 +259,11 @@ function goStore() { } function goCave() { - console.log("Going to cave."); + console.log("Going to cave."); } function fightDragon() { - console.log("Fighting dragon."); + console.log("Fighting dragon."); } function buyHealth() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-46.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-46.md index 4455a29ee6..b9ac64b9ba 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-46.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-46.md @@ -59,18 +59,18 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + } ]; // initialize buttons @@ -78,14 +78,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -230,24 +230,24 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -255,14 +255,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -274,11 +274,11 @@ function goStore() { } function goCave() { - console.log("Going to cave."); + console.log("Going to cave."); } function fightDragon() { - console.log("Fighting dragon."); + console.log("Fighting dragon."); } function buyHealth() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-47.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-47.md index 9035d30db7..4a2e5170e7 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-47.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-47.md @@ -56,24 +56,24 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -81,14 +81,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -233,24 +233,24 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -258,14 +258,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -277,11 +277,11 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function fightDragon() { - console.log("Fighting dragon."); + console.log("Fighting dragon."); } function buyHealth() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-48.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-48.md index d9b31809b2..9b08c87c79 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-48.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-48.md @@ -56,24 +56,24 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -81,14 +81,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -228,24 +228,24 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -253,14 +253,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -272,11 +272,11 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function fightDragon() { - console.log("Fighting dragon."); + console.log("Fighting dragon."); } function buyHealth() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-49.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-49.md index b46279d184..a2de6c1136 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-49.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-49.md @@ -59,24 +59,24 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -84,14 +84,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -237,24 +237,24 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -262,14 +262,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -281,11 +281,11 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function fightDragon() { - console.log("Fighting dragon."); + console.log("Fighting dragon."); } function buyHealth() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-50.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-50.md index e14a26ba5a..212cb8304d 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-50.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-50.md @@ -57,24 +57,24 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -82,14 +82,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -236,24 +236,24 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -261,14 +261,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -280,11 +280,11 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function fightDragon() { - console.log("Fighting dragon."); + console.log("Fighting dragon."); } function buyHealth() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-51.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-51.md index 5fad33d01a..62815bd37a 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-51.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-51.md @@ -58,24 +58,24 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -83,14 +83,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -238,24 +238,24 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -263,14 +263,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -282,11 +282,11 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function fightDragon() { - console.log("Fighting dragon."); + console.log("Fighting dragon."); } function buyHealth() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-52.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-52.md index 6251e74048..24cfa5bf3c 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-52.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-52.md @@ -57,24 +57,24 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -82,14 +82,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -237,24 +237,24 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -262,14 +262,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -281,18 +281,18 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function fightDragon() { - console.log("Fighting dragon."); + console.log("Fighting dragon."); } function buyHealth() { - gold -= 10; - health += 10; - goldText.innerText = gold; - healthText.innerText = health; + gold -= 10; + health += 10; + goldText.innerText = gold; + healthText.innerText = health; } function buyWeapon() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-53.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-53.md index f690c3e01e..a6331a767e 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-53.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-53.md @@ -12,9 +12,9 @@ What if the player doesn't have enough gold to buy health? Put all the code in t ```js function checkMoney() { - if (condition) { - console.log("You have money!"); - } + if (condition) { + console.log("You have money!"); + } } ``` @@ -67,24 +67,24 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -92,14 +92,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -119,10 +119,10 @@ function fightDragon() { } function buyHealth() { - gold -= 10; - health += 10; - goldText.innerText = gold; - healthText.innerText = health; + gold -= 10; + health += 10; + goldText.innerText = gold; + healthText.innerText = health; } function buyWeapon() { @@ -249,24 +249,24 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -274,14 +274,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -293,11 +293,11 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function fightDragon() { - console.log("Fighting dragon."); + console.log("Fighting dragon."); } function buyHealth() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-54.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-54.md index f66a4ef262..86e45223c2 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-54.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-54.md @@ -14,7 +14,7 @@ Here is an `if` statement that checks if `num` is greater than or equal to 5: ```js if (num >= 5) { - console.log("Num is greater than or equal to five!"); + console.log("Num is greater than or equal to five!"); } ``` @@ -64,24 +64,24 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -89,14 +89,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -248,24 +248,24 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -273,14 +273,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -292,11 +292,11 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function fightDragon() { - console.log("Fighting dragon."); + console.log("Fighting dragon."); } function buyHealth() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-55.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-55.md index 40b626e3bb..f9b6a3372c 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-55.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-55.md @@ -14,7 +14,7 @@ Here is an example of an empty `else` statement: ```js if (num >= 5) { - console.log("Num is greater than or equal to five!"); + console.log("Num is greater than or equal to five!"); } else { } ``` @@ -65,24 +65,24 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -90,14 +90,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -249,24 +249,24 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -274,14 +274,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -293,11 +293,11 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function fightDragon() { - console.log("Fighting dragon."); + console.log("Fighting dragon."); } function buyHealth() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-56.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-56.md index 22f0d63133..96ba2dd710 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-56.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-56.md @@ -58,24 +58,24 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -83,14 +83,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -244,24 +244,24 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -269,14 +269,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -288,11 +288,11 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function fightDragon() { - console.log("Fighting dragon."); + console.log("Fighting dragon."); } function buyHealth() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-57.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-57.md index 6a98f2c679..52b1b733b0 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-57.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-57.md @@ -56,24 +56,24 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -81,14 +81,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -244,24 +244,24 @@ const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = []; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -269,14 +269,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -288,11 +288,11 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function fightDragon() { - console.log("Fighting dragon."); + console.log("Fighting dragon."); } function buyHealth() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-58.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-58.md index 351090734c..d6cde56965 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-58.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-58.md @@ -59,24 +59,24 @@ const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = []; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -84,14 +84,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -245,43 +245,43 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -289,14 +289,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -308,11 +308,11 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function fightDragon() { - console.log("Fighting dragon."); + console.log("Fighting dragon."); } function buyHealth() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-59.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-59.md index afc47364b3..2c30daad99 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-59.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-59.md @@ -56,43 +56,43 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -100,14 +100,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -261,43 +261,43 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -305,14 +305,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -324,11 +324,11 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function fightDragon() { - console.log("Fighting dragon."); + console.log("Fighting dragon."); } function buyHealth() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-60.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-60.md index 6035f99917..5e43a1dff7 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-60.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-60.md @@ -57,43 +57,43 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -101,14 +101,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -265,43 +265,43 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -309,14 +309,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -328,11 +328,11 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function fightDragon() { - console.log("Fighting dragon."); + console.log("Fighting dragon."); } function buyHealth() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-61.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-61.md index 8ececcfd14..87cc6e0688 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-61.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-61.md @@ -57,43 +57,43 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -101,14 +101,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -265,43 +265,43 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -309,14 +309,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -328,11 +328,11 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function fightDragon() { - console.log("Fighting dragon."); + console.log("Fighting dragon."); } function buyHealth() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-62.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-62.md index adea6c44f1..3d6bf38b3c 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-62.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-62.md @@ -64,43 +64,43 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -108,14 +108,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -273,43 +273,43 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -317,14 +317,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -336,11 +336,11 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function fightDragon() { - console.log("Fighting dragon."); + console.log("Fighting dragon."); } function buyHealth() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-63.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-63.md index e140349fe4..0892f06217 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-63.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-63.md @@ -58,43 +58,43 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -102,14 +102,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -267,43 +267,43 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -311,14 +311,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -330,11 +330,11 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function fightDragon() { - console.log("Fighting dragon."); + console.log("Fighting dragon."); } function buyHealth() { @@ -349,12 +349,12 @@ function buyHealth() { } function buyWeapon() { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - text.innerText = "You now have a new weapon."; - } + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + text.innerText = "You now have a new weapon."; + } } function fightSlime() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-64.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-64.md index b3c035cf8a..4dceeb0f89 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-64.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-64.md @@ -56,43 +56,43 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -100,14 +100,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -138,12 +138,12 @@ function buyHealth() { } function buyWeapon() { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - text.innerText = "You now have a new weapon."; - } + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + text.innerText = "You now have a new weapon."; + } } function fightSlime() { @@ -267,43 +267,43 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -311,14 +311,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -330,11 +330,11 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function fightDragon() { - console.log("Fighting dragon."); + console.log("Fighting dragon."); } function buyHealth() { @@ -349,13 +349,13 @@ function buyHealth() { } function buyWeapon() { - if (gold >= 30) { - gold -= 30; - currentWeapon++; + if (gold >= 30) { + gold -= 30; + currentWeapon++; goldText.innerText = gold; let newWeapon = weapons; - text.innerText = "You now have a new weapon."; - } + text.innerText = "You now have a new weapon."; + } } function fightSlime() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-65.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-65.md index bef5e7bef5..826e3f287d 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-65.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-65.md @@ -56,43 +56,43 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -100,14 +100,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -138,13 +138,13 @@ function buyHealth() { } function buyWeapon() { - if (gold >= 30) { - gold -= 30; - currentWeapon++; + if (gold >= 30) { + gold -= 30; + currentWeapon++; goldText.innerText = gold; let newWeapon = weapons; - text.innerText = "You now have a new weapon."; - } + text.innerText = "You now have a new weapon."; + } } function fightSlime() { @@ -268,43 +268,43 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -312,14 +312,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -331,11 +331,11 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function fightDragon() { - console.log("Fighting dragon."); + console.log("Fighting dragon."); } function buyHealth() { @@ -350,13 +350,13 @@ function buyHealth() { } function buyWeapon() { - if (gold >= 30) { - gold -= 30; - currentWeapon++; + if (gold >= 30) { + gold -= 30; + currentWeapon++; goldText.innerText = gold; let newWeapon = weapons[currentWeapon]; - text.innerText = "You now have a new weapon."; - } + text.innerText = "You now have a new weapon."; + } } function fightSlime() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-66.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-66.md index b26f7b5757..60cd550717 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-66.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-66.md @@ -56,43 +56,43 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -100,14 +100,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -138,13 +138,13 @@ function buyHealth() { } function buyWeapon() { - if (gold >= 30) { - gold -= 30; - currentWeapon++; + if (gold >= 30) { + gold -= 30; + currentWeapon++; goldText.innerText = gold; let newWeapon = weapons[currentWeapon]; - text.innerText = "You now have a new weapon."; - } + text.innerText = "You now have a new weapon."; + } } function fightSlime() { @@ -268,43 +268,43 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -312,14 +312,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -331,11 +331,11 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function fightDragon() { - console.log("Fighting dragon."); + console.log("Fighting dragon."); } function buyHealth() { @@ -350,13 +350,13 @@ function buyHealth() { } function buyWeapon() { - if (gold >= 30) { - gold -= 30; - currentWeapon++; + if (gold >= 30) { + gold -= 30; + currentWeapon++; goldText.innerText = gold; let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a new weapon."; - } + text.innerText = "You now have a new weapon."; + } } function fightSlime() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-67.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-67.md index 1a2a942f04..fa5eceff4e 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-67.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-67.md @@ -63,43 +63,43 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -107,14 +107,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -145,13 +145,13 @@ function buyHealth() { } function buyWeapon() { - if (gold >= 30) { - gold -= 30; - currentWeapon++; + if (gold >= 30) { + gold -= 30; + currentWeapon++; goldText.innerText = gold; let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a new weapon."; - } + text.innerText = "You now have a new weapon."; + } } function fightSlime() { @@ -275,43 +275,43 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -319,14 +319,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -338,11 +338,11 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function fightDragon() { - console.log("Fighting dragon."); + console.log("Fighting dragon."); } function buyHealth() { @@ -357,13 +357,13 @@ function buyHealth() { } function buyWeapon() { - if (gold >= 30) { - gold -= 30; - currentWeapon++; + if (gold >= 30) { + gold -= 30; + currentWeapon++; goldText.innerText = gold; let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - } + text.innerText = "You now have a " + newWeapon + "."; + } } function fightSlime() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-68.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-68.md index 2a19cf6c81..060e0bb670 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-68.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-68.md @@ -64,43 +64,43 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -108,14 +108,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -146,13 +146,13 @@ function buyHealth() { } function buyWeapon() { - if (gold >= 30) { - gold -= 30; - currentWeapon++; + if (gold >= 30) { + gold -= 30; + currentWeapon++; goldText.innerText = gold; let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - } + text.innerText = "You now have a " + newWeapon + "."; + } } function fightSlime() { @@ -276,43 +276,43 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -320,14 +320,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -339,11 +339,11 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function fightDragon() { - console.log("Fighting dragon."); + console.log("Fighting dragon."); } function buyHealth() { @@ -358,14 +358,14 @@ function buyHealth() { } function buyWeapon() { - if (gold >= 30) { - gold -= 30; - currentWeapon++; + if (gold >= 30) { + gold -= 30; + currentWeapon++; goldText.innerText = gold; let newWeapon = weapons[currentWeapon].name; text.innerText = "You now have a " + newWeapon + "."; inventory.push(newWeapon); - } + } } function fightSlime() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-69.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-69.md index a96cfb7e91..31af1c3d62 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-69.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-69.md @@ -57,43 +57,43 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -101,14 +101,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -139,14 +139,14 @@ function buyHealth() { } function buyWeapon() { - if (gold >= 30) { - gold -= 30; - currentWeapon++; + if (gold >= 30) { + gold -= 30; + currentWeapon++; goldText.innerText = gold; let newWeapon = weapons[currentWeapon].name; text.innerText = "You now have a " + newWeapon + "."; inventory.push(newWeapon); - } + } } function fightSlime() { @@ -270,43 +270,43 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -314,14 +314,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -333,11 +333,11 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function fightDragon() { - console.log("Fighting dragon."); + console.log("Fighting dragon."); } function buyHealth() { @@ -352,15 +352,15 @@ function buyHealth() { } function buyWeapon() { - if (gold >= 30) { - gold -= 30; - currentWeapon++; + if (gold >= 30) { + gold -= 30; + currentWeapon++; goldText.innerText = gold; let newWeapon = weapons[currentWeapon].name; text.innerText = "You now have a " + newWeapon + "."; inventory.push(newWeapon); text.innerText += " In your inventory you have: "; - } + } } function fightSlime() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-70.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-70.md index 705a4efba0..1ef243c331 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-70.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-70.md @@ -57,43 +57,43 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -101,14 +101,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -139,15 +139,15 @@ function buyHealth() { } function buyWeapon() { - if (gold >= 30) { - gold -= 30; - currentWeapon++; + if (gold >= 30) { + gold -= 30; + currentWeapon++; goldText.innerText = gold; let newWeapon = weapons[currentWeapon].name; text.innerText = "You now have a " + newWeapon + "."; inventory.push(newWeapon); text.innerText += " In your inventory you have: "; - } + } } function fightSlime() { @@ -271,43 +271,43 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -315,14 +315,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -334,11 +334,11 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function fightDragon() { - console.log("Fighting dragon."); + console.log("Fighting dragon."); } function buyHealth() { @@ -353,15 +353,15 @@ function buyHealth() { } function buyWeapon() { - if (gold >= 30) { - gold -= 30; - currentWeapon++; + if (gold >= 30) { + gold -= 30; + currentWeapon++; goldText.innerText = gold; let newWeapon = weapons[currentWeapon].name; text.innerText = "You now have a " + newWeapon + "."; inventory.push(newWeapon); text.innerText += " In your inventory you have: " + inventory; - } + } } function fightSlime() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-71.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-71.md index c3a4609b0e..a9fef0cf8a 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-71.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-71.md @@ -56,43 +56,43 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -100,14 +100,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -138,7 +138,7 @@ function buyHealth() { } function buyWeapon() { - if (gold >= 30) { + if (gold >= 30) { gold -= 30; currentWeapon++; goldText.innerText = gold; @@ -146,7 +146,7 @@ function buyWeapon() { text.innerText = "You now have a " + newWeapon + "."; inventory.push(newWeapon); text.innerText += " In your inventory you have: " + inventory; - } + } } function fightSlime() { @@ -270,43 +270,43 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -314,14 +314,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -333,11 +333,11 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function fightDragon() { - console.log("Fighting dragon."); + console.log("Fighting dragon."); } function buyHealth() { @@ -352,15 +352,15 @@ function buyHealth() { } function buyWeapon() { - if (gold >= 30) { - gold -= 30; - currentWeapon++; + if (gold >= 30) { + gold -= 30; + currentWeapon++; goldText.innerText = gold; let newWeapon = weapons[currentWeapon].name; text.innerText = "You now have a " + newWeapon + "."; inventory.push(newWeapon); text.innerText += " In your inventory you have: " + inventory; - } else { + } else { text.innerText = "You do not have enough gold to buy a weapon."; } } diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-72.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-72.md index d0c993d664..b0ef0bb66c 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-72.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-72.md @@ -56,43 +56,43 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -100,14 +100,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -138,15 +138,15 @@ function buyHealth() { } function buyWeapon() { - if (gold >= 30) { - gold -= 30; - currentWeapon++; + if (gold >= 30) { + gold -= 30; + currentWeapon++; goldText.innerText = gold; let newWeapon = weapons[currentWeapon].name; text.innerText = "You now have a " + newWeapon + "."; inventory.push(newWeapon); text.innerText += " In your inventory you have: " + inventory; - } else { + } else { text.innerText = "You do not have enough gold to buy a weapon."; } } @@ -272,43 +272,43 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -316,14 +316,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -335,11 +335,11 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function fightDragon() { - console.log("Fighting dragon."); + console.log("Fighting dragon."); } function buyHealth() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-73.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-73.md index dce05ab272..647ccf262f 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-73.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-73.md @@ -56,43 +56,43 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -100,14 +100,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -274,43 +274,43 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -318,14 +318,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -337,11 +337,11 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function fightDragon() { - console.log("Fighting dragon."); + console.log("Fighting dragon."); } function buyHealth() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-74.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-74.md index aea2eb9464..11e934b26a 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-74.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-74.md @@ -56,43 +56,43 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -100,14 +100,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -274,43 +274,43 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -318,14 +318,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -337,11 +337,11 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function fightDragon() { - console.log("Fighting dragon."); + console.log("Fighting dragon."); } function buyHealth() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-75.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-75.md index 8135e268f9..61f6b7c1af 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-75.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-75.md @@ -56,43 +56,43 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -100,14 +100,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -274,43 +274,43 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -318,14 +318,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -337,11 +337,11 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function fightDragon() { - console.log("Fighting dragon."); + console.log("Fighting dragon."); } function buyHealth() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-76.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-76.md index aa3c5fa0d7..a990e50e1b 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-76.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-76.md @@ -56,43 +56,43 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -100,14 +100,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -276,43 +276,43 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -320,14 +320,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -339,11 +339,11 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function fightDragon() { - console.log("Fighting dragon."); + console.log("Fighting dragon."); } function buyHealth() { @@ -358,23 +358,23 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function fightSlime() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-77.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-77.md index 60906ce901..6b267d6417 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-77.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-77.md @@ -56,43 +56,43 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -100,14 +100,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -138,23 +138,23 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function fightSlime() { @@ -278,43 +278,43 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -322,14 +322,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -341,11 +341,11 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function fightDragon() { - console.log("Fighting dragon."); + console.log("Fighting dragon."); } function buyHealth() { @@ -360,23 +360,23 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-78.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-78.md index 6b8d6605d6..234b2b240a 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-78.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-78.md @@ -56,43 +56,43 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -100,14 +100,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -138,23 +138,23 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { @@ -281,43 +281,43 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -325,14 +325,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -344,11 +344,11 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function fightDragon() { - console.log("Fighting dragon."); + console.log("Fighting dragon."); } function buyHealth() { @@ -363,23 +363,23 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-79.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-79.md index b632246a91..7edd0e6d0a 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-79.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-79.md @@ -56,43 +56,43 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -100,14 +100,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -138,29 +138,29 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { + if (inventory.length > 1) { - } + } } function fightSlime() { @@ -284,43 +284,43 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -328,14 +328,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -347,11 +347,11 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function fightDragon() { - console.log("Fighting dragon."); + console.log("Fighting dragon."); } function buyHealth() { @@ -366,23 +366,23 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-80.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-80.md index 7325ed0511..efa720a9d5 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-80.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-80.md @@ -56,43 +56,43 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -100,14 +100,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -138,23 +138,23 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { @@ -285,43 +285,43 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -329,14 +329,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -348,11 +348,11 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function fightDragon() { - console.log("Fighting dragon."); + console.log("Fighting dragon."); } function buyHealth() { @@ -367,23 +367,23 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-81.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-81.md index d14b470ed0..b86df14320 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-81.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-81.md @@ -64,43 +64,43 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -108,14 +108,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -146,23 +146,23 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { @@ -294,43 +294,43 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -338,14 +338,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -357,11 +357,11 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function fightDragon() { - console.log("Fighting dragon."); + console.log("Fighting dragon."); } function buyHealth() { @@ -376,23 +376,23 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-82.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-82.md index 691b0e50e2..233f94e9a1 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-82.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-82.md @@ -56,43 +56,43 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -100,14 +100,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -138,23 +138,23 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { @@ -287,43 +287,43 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -331,14 +331,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -350,11 +350,11 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function fightDragon() { - console.log("Fighting dragon."); + console.log("Fighting dragon."); } function buyHealth() { @@ -369,23 +369,23 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-83.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-83.md index 0918a50a39..169f451b2f 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-83.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-83.md @@ -57,43 +57,43 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -101,14 +101,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -139,23 +139,23 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { @@ -289,43 +289,43 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -333,14 +333,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -352,11 +352,11 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function fightDragon() { - console.log("Fighting dragon."); + console.log("Fighting dragon."); } function buyHealth() { @@ -371,23 +371,23 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { @@ -396,7 +396,7 @@ function sellWeapon() { goldText.innerText = gold; let currentWeapon = inventory.shift(); text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; + text.innerText += " In your inventory you have: " + inventory; } } diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-84.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-84.md index 9211a334b5..41c6c1645f 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-84.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-84.md @@ -56,43 +56,43 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -100,14 +100,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -138,23 +138,23 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { @@ -163,7 +163,7 @@ function sellWeapon() { goldText.innerText = gold; let currentWeapon = inventory.shift(); text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; + text.innerText += " In your inventory you have: " + inventory; } } @@ -288,43 +288,43 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -332,14 +332,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -351,11 +351,11 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function fightDragon() { - console.log("Fighting dragon."); + console.log("Fighting dragon."); } function buyHealth() { @@ -370,35 +370,35 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-85.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-85.md index a9ba478509..bff8f14616 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-85.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-85.md @@ -59,43 +59,43 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -103,14 +103,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -141,35 +141,35 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { @@ -293,22 +293,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -330,24 +330,24 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -355,14 +355,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -374,7 +374,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -389,35 +389,35 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { @@ -427,7 +427,7 @@ function fightBeast() { } function fightDragon() { - console.log("Fighting dragon."); + console.log("Fighting dragon."); } ``` diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-86.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-86.md index f201fd43da..351b3f5417 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-86.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-86.md @@ -56,22 +56,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -93,24 +93,24 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -118,14 +118,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -152,35 +152,35 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { @@ -308,22 +308,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -345,24 +345,24 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -370,14 +370,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -389,7 +389,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -404,35 +404,35 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { @@ -442,7 +442,7 @@ function fightBeast() { } function fightDragon() { - console.log("Fighting dragon."); + console.log("Fighting dragon."); } function goFight() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-87.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-87.md index ae482e5cbe..ec4951f39f 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-87.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-87.md @@ -58,22 +58,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -95,24 +95,24 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -120,14 +120,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -154,35 +154,35 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { @@ -313,22 +313,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -350,24 +350,24 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -375,14 +375,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -394,7 +394,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -409,47 +409,47 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { } function fightDragon() { - console.log("Fighting dragon."); + console.log("Fighting dragon."); } function goFight() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-88.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-88.md index 6ff286df4f..9245a85ac2 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-88.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-88.md @@ -56,22 +56,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -93,24 +93,24 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -118,14 +118,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -152,40 +152,40 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { @@ -313,22 +313,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -350,24 +350,24 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -375,14 +375,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -394,7 +394,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -409,50 +409,50 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-89.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-89.md index 97d4bbf09a..84ce836aa8 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-89.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-89.md @@ -57,22 +57,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -94,24 +94,24 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + } ]; // initialize buttons @@ -119,14 +119,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -153,50 +153,50 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { @@ -322,22 +322,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -359,30 +359,30 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + } ]; // initialize buttons @@ -390,14 +390,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -409,7 +409,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -424,50 +424,50 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-90.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-90.md index 190a5a6bdf..c5c7ff369b 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-90.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-90.md @@ -56,22 +56,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -93,30 +93,30 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + } ]; // initialize buttons @@ -124,14 +124,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -158,50 +158,50 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { @@ -322,22 +322,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -359,30 +359,30 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + } ]; // initialize buttons @@ -390,14 +390,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -409,7 +409,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -424,50 +424,50 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-91.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-91.md index ac6f48b72e..0483807150 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-91.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-91.md @@ -56,22 +56,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -93,30 +93,30 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + } ]; // initialize buttons @@ -124,14 +124,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -158,50 +158,50 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { @@ -328,22 +328,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -365,30 +365,30 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + } ]; // initialize buttons @@ -396,14 +396,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -415,7 +415,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -430,50 +430,50 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-92.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-92.md index f1e8cb1de6..b0caf75d5c 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-92.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-92.md @@ -56,22 +56,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -93,30 +93,30 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + } ]; // initialize buttons @@ -124,14 +124,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -158,50 +158,50 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { @@ -329,22 +329,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -366,30 +366,30 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + } ]; // initialize buttons @@ -397,14 +397,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -416,7 +416,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -431,50 +431,50 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-93.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-93.md index b2b3c34526..f6c9d8b2e8 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-93.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-93.md @@ -58,22 +58,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -95,30 +95,30 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + } ]; // initialize buttons @@ -126,14 +126,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -160,50 +160,50 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { @@ -332,22 +332,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -369,30 +369,30 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + } ]; // initialize buttons @@ -400,14 +400,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -419,7 +419,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -434,56 +434,56 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; } function attack() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-94.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-94.md index 1f56fe65d2..15de213cf8 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-94.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-94.md @@ -56,22 +56,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -93,30 +93,30 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + } ]; // initialize buttons @@ -124,14 +124,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -158,56 +158,56 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; } function attack() { @@ -331,22 +331,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -368,30 +368,30 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + } ]; // initialize buttons @@ -399,14 +399,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -418,7 +418,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -433,58 +433,58 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-95.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-95.md index 84880076ac..cc9b6d4050 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-95.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-95.md @@ -56,22 +56,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -93,30 +93,30 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + } ]; // initialize buttons @@ -124,14 +124,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -158,58 +158,58 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { @@ -333,22 +333,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -370,30 +370,30 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + } ]; // initialize buttons @@ -401,14 +401,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -420,7 +420,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -435,62 +435,62 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText = "The " + monsters[fighting].name + " attacks."; } function dodge() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-96.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-96.md index 2a75969b0e..962a9d5d88 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-96.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-96.md @@ -56,22 +56,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -93,30 +93,30 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + } ]; // initialize buttons @@ -124,14 +124,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -158,62 +158,62 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText = "The " + monsters[fighting].name + " attacks."; } function dodge() { @@ -334,22 +334,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -371,30 +371,30 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + } ]; // initialize buttons @@ -402,14 +402,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -421,7 +421,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -436,63 +436,63 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; } function dodge() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-97.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-97.md index 594b1096b5..b319314e8a 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-97.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-97.md @@ -56,22 +56,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -93,30 +93,30 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + } ]; // initialize buttons @@ -124,14 +124,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -158,63 +158,63 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; } function dodge() { @@ -335,22 +335,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -372,30 +372,30 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + } ]; // initialize buttons @@ -403,14 +403,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -422,7 +422,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -437,64 +437,64 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= monsters[fighting].level; + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= monsters[fighting].level; } function dodge() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-98.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-98.md index e379de2cef..b0a460f397 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-98.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-98.md @@ -56,22 +56,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -93,30 +93,30 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + } ]; // initialize buttons @@ -124,14 +124,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -158,64 +158,64 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= monsters[fighting].level; + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= monsters[fighting].level; } function dodge() { @@ -336,22 +336,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -373,30 +373,30 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + } ]; // initialize buttons @@ -404,14 +404,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -423,7 +423,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -438,65 +438,65 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= monsters[fighting].level; - monsterHealth -= weapons[currentWeapon].power; + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= monsters[fighting].level; + monsterHealth -= weapons[currentWeapon].power; } function dodge() { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-99.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-99.md index 417cd536ee..20cb51be93 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-99.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript-rpg-game/part-99.md @@ -58,22 +58,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -95,30 +95,30 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + } ]; // initialize buttons @@ -126,14 +126,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -160,65 +160,65 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= monsters[fighting].level; - monsterHealth -= weapons[currentWeapon].power; + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= monsters[fighting].level; + monsterHealth -= weapons[currentWeapon].power; } function dodge() { @@ -339,22 +339,22 @@ const monsterNameText = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { - name: "stick", - power: 5 - }, - { - name: "dagger", - power: 30 - }, - { - name: "claw hammer", - power: 50 - }, - { - name: "sword", - power: 100 - } + { + name: "stick", + power: 5 + }, + { + name: "dagger", + power: 30 + }, + { + name: "claw hammer", + power: 50 + }, + { + name: "sword", + power: 100 + } ]; const monsters = [ @@ -376,30 +376,30 @@ const monsters = [ ]; const locations = [ - { - name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], - "button functions": [goStore, goCave, fightDragon], - text: "You are in the town square. You see a sign that says \"Store.\"" - }, - { - name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], - "button functions": [buyHealth, buyWeapon, goTown], - text: "You enter the store." - }, - { - name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], - "button functions": [fightSlime, fightBeast, goTown], - text: "You enter the cave. You see some monsters." - }, - { - name: "fight", - "button text": ["Attack", "Dodge", "Run"], - "button functions": [attack, dodge, goTown], - text: "You are fighting a monster." - } + { + name: "town square", + "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button functions": [goStore, goCave, fightDragon], + text: "You are in the town square. You see a sign that says \"Store.\"" + }, + { + name: "store", + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button functions": [buyHealth, buyWeapon, goTown], + text: "You enter the store." + }, + { + name: "cave", + "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button functions": [fightSlime, fightBeast, goTown], + text: "You enter the cave. You see some monsters." + }, + { + name: "fight", + "button text": ["Attack", "Dodge", "Run"], + "button functions": [attack, dodge, goTown], + text: "You are fighting a monster." + } ]; // initialize buttons @@ -407,14 +407,14 @@ button1.onclick = goStore; button2.onclick = goCave; button3.onclick = fightDragon; -function update(location) { - button1.innerText = location["button text"][0]; - button2.innerText = location["button text"][1]; - button3.innerText = location["button text"][2]; - button1.onclick = location["button functions"][0]; - button2.onclick = location["button functions"][1]; - button3.onclick = location["button functions"][2]; - text.innerText = location.text; +function update(location) { + button1.innerText = location["button text"][0]; + button2.innerText = location["button text"][1]; + button3.innerText = location["button text"][2]; + button1.onclick = location["button functions"][0]; + button2.onclick = location["button functions"][1]; + button3.onclick = location["button functions"][2]; + text.innerText = location.text; } function goTown() { @@ -426,7 +426,7 @@ function goStore() { } function goCave() { - update(locations[2]); + update(locations[2]); } function buyHealth() { @@ -441,65 +441,65 @@ function buyHealth() { } function buyWeapon() { - if (currentWeapon < weapons.length - 1) { - if (gold >= 30) { - gold -= 30; - currentWeapon++; - goldText.innerText = gold; - let newWeapon = weapons[currentWeapon].name; - text.innerText = "You now have a " + newWeapon + "."; - inventory.push(newWeapon); - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "You do not have enough gold to buy a weapon."; - } - } else { - text.innerText = "You already have the most powerful weapon!"; - button2.innerText = "Sell weapon for 15 gold"; - button2.onclick = sellWeapon; - } + if (currentWeapon < weapons.length - 1) { + if (gold >= 30) { + gold -= 30; + currentWeapon++; + goldText.innerText = gold; + let newWeapon = weapons[currentWeapon].name; + text.innerText = "You now have a " + newWeapon + "."; + inventory.push(newWeapon); + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "You do not have enough gold to buy a weapon."; + } + } else { + text.innerText = "You already have the most powerful weapon!"; + button2.innerText = "Sell weapon for 15 gold"; + button2.onclick = sellWeapon; + } } function sellWeapon() { - if (inventory.length > 1) { - gold += 15; - goldText.innerText = gold; - let currentWeapon = inventory.shift(); - text.innerText = "You sold a " + currentWeapon + "."; - text.innerText += " In your inventory you have: " + inventory; - } else { - text.innerText = "Don't sell your only weapon!"; - } + if (inventory.length > 1) { + gold += 15; + goldText.innerText = gold; + let currentWeapon = inventory.shift(); + text.innerText = "You sold a " + currentWeapon + "."; + text.innerText += " In your inventory you have: " + inventory; + } else { + text.innerText = "Don't sell your only weapon!"; + } } function fightSlime() { - fighting = 0; - goFight(); + fighting = 0; + goFight(); } function fightBeast() { - fighting = 1; - goFight(); + fighting = 1; + goFight(); } function fightDragon() { - fighting = 2; - goFight(); + fighting = 2; + goFight(); } function goFight() { - update(locations[3]); - monsterHealth = monsters[fighting].health; - monsterStats.style.display = "block"; - monsterNameText.innerText = monsters[fighting].name; - monsterHealthText.innerText = monsterHealth; + update(locations[3]); + monsterHealth = monsters[fighting].health; + monsterStats.style.display = "block"; + monsterNameText.innerText = monsters[fighting].name; + monsterHealthText.innerText = monsterHealth; } function attack() { - text.innerText = "The " + monsters[fighting].name + " attacks."; - text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; - health -= monsters[fighting].level; - monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; + text.innerText = "The " + monsters[fighting].name + " attacks."; + text.innerText += " You attack it with your " + weapons[currentWeapon].name + "."; + health -= monsters[fighting].level; + monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1; } function dodge() {