mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-03-24 11:03:17 -04:00
fix(curriculum): remove anti-pattern ternary use in rpg game (#53070)
Co-authored-by: Jessica Wilkins <67210629+jdwilkin4@users.noreply.github.com> Co-authored-by: Huyen Nguyen <25715018+huyenltnguyen@users.noreply.github.com>
This commit is contained in:
@@ -569,152 +569,148 @@
|
||||
"title": "Step 139"
|
||||
},
|
||||
{
|
||||
"id": "62a8f2bc37675e77d5835235",
|
||||
"id": "62a8f35bde1750791f58773f",
|
||||
"title": "Step 140"
|
||||
},
|
||||
{
|
||||
"id": "62a8f35bde1750791f58773f",
|
||||
"id": "62a94114ce0b8918b487390f",
|
||||
"title": "Step 141"
|
||||
},
|
||||
{
|
||||
"id": "62a94114ce0b8918b487390f",
|
||||
"id": "62aa1cea594f152ba626b872",
|
||||
"title": "Step 142"
|
||||
},
|
||||
{
|
||||
"id": "62aa1cea594f152ba626b872",
|
||||
"id": "62aa1d6736ba262cfa74344b",
|
||||
"title": "Step 143"
|
||||
},
|
||||
{
|
||||
"id": "62aa1d6736ba262cfa74344b",
|
||||
"id": "62aa1d9f535e102e4663e7a6",
|
||||
"title": "Step 144"
|
||||
},
|
||||
{
|
||||
"id": "62aa1d9f535e102e4663e7a6",
|
||||
"id": "62aa1e3c7c3d552fb04f0f18",
|
||||
"title": "Step 145"
|
||||
},
|
||||
{
|
||||
"id": "62aa1e3c7c3d552fb04f0f18",
|
||||
"id": "62aa1e8ccd579330e097ce44",
|
||||
"title": "Step 146"
|
||||
},
|
||||
{
|
||||
"id": "62aa1e8ccd579330e097ce44",
|
||||
"id": "62aa1eec891ed731db227a36",
|
||||
"title": "Step 147"
|
||||
},
|
||||
{
|
||||
"id": "62aa1eec891ed731db227a36",
|
||||
"id": "62aa1fed3d4e873366ff3131",
|
||||
"title": "Step 148"
|
||||
},
|
||||
{
|
||||
"id": "62aa1fed3d4e873366ff3131",
|
||||
"id": "62aa204c1e1d33348ff09944",
|
||||
"title": "Step 149"
|
||||
},
|
||||
{
|
||||
"id": "62aa204c1e1d33348ff09944",
|
||||
"id": "62aa20e9cf1be9358f5aceae",
|
||||
"title": "Step 150"
|
||||
},
|
||||
{
|
||||
"id": "62aa20e9cf1be9358f5aceae",
|
||||
"id": "62aa2136fc49b836dfedb959",
|
||||
"title": "Step 151"
|
||||
},
|
||||
{
|
||||
"id": "62aa2136fc49b836dfedb959",
|
||||
"id": "62aa21971e3b743844849985",
|
||||
"title": "Step 152"
|
||||
},
|
||||
{
|
||||
"id": "62aa21971e3b743844849985",
|
||||
"id": "62aa21ea8d9d9f396b95dd87",
|
||||
"title": "Step 153"
|
||||
},
|
||||
{
|
||||
"id": "62aa21ea8d9d9f396b95dd87",
|
||||
"id": "62aa226207f33d3ad4c6f546",
|
||||
"title": "Step 154"
|
||||
},
|
||||
{
|
||||
"id": "62aa226207f33d3ad4c6f546",
|
||||
"id": "62aa22aba186563bcbf2c395",
|
||||
"title": "Step 155"
|
||||
},
|
||||
{
|
||||
"id": "62aa22aba186563bcbf2c395",
|
||||
"id": "62aa234322d4ad3e8bce42cc",
|
||||
"title": "Step 156"
|
||||
},
|
||||
{
|
||||
"id": "62aa234322d4ad3e8bce42cc",
|
||||
"id": "62aa2469c77b363fdb4f0e06",
|
||||
"title": "Step 157"
|
||||
},
|
||||
{
|
||||
"id": "62aa2469c77b363fdb4f0e06",
|
||||
"id": "62aa252c3b1073415ba2b898",
|
||||
"title": "Step 158"
|
||||
},
|
||||
{
|
||||
"id": "62aa252c3b1073415ba2b898",
|
||||
"id": "62aa258da314ef42ba0a1858",
|
||||
"title": "Step 159"
|
||||
},
|
||||
{
|
||||
"id": "62aa258da314ef42ba0a1858",
|
||||
"id": "62aa25fcb5837d43b4d9873d",
|
||||
"title": "Step 160"
|
||||
},
|
||||
{
|
||||
"id": "62aa25fcb5837d43b4d9873d",
|
||||
"id": "62aa2626c3c10244b94c787b",
|
||||
"title": "Step 161"
|
||||
},
|
||||
{
|
||||
"id": "62aa2626c3c10244b94c787b",
|
||||
"id": "62aa264d23cdaa45a20efada",
|
||||
"title": "Step 162"
|
||||
},
|
||||
{
|
||||
"id": "62aa264d23cdaa45a20efada",
|
||||
"id": "62aa26cca3cd3d46c431e73b",
|
||||
"title": "Step 163"
|
||||
},
|
||||
{
|
||||
"id": "62aa26cca3cd3d46c431e73b",
|
||||
"id": "62aa27227399d647e1c37a3c",
|
||||
"title": "Step 164"
|
||||
},
|
||||
{
|
||||
"id": "62aa27227399d647e1c37a3c",
|
||||
"id": "62aa27560def7048d7b4a095",
|
||||
"title": "Step 165"
|
||||
},
|
||||
{
|
||||
"id": "62aa27560def7048d7b4a095",
|
||||
"id": "62aa27c40ca6f04ab8be5fac",
|
||||
"title": "Step 166"
|
||||
},
|
||||
{
|
||||
"id": "62aa27c40ca6f04ab8be5fac",
|
||||
"id": "62aa28032d863d4bd8058799",
|
||||
"title": "Step 167"
|
||||
},
|
||||
{
|
||||
"id": "62aa28032d863d4bd8058799",
|
||||
"id": "62aa287434dc284cea01157c",
|
||||
"title": "Step 168"
|
||||
},
|
||||
{
|
||||
"id": "62aa287434dc284cea01157c",
|
||||
"id": "62aa28bbd6323e4dfb3ac43e",
|
||||
"title": "Step 169"
|
||||
},
|
||||
{
|
||||
"id": "62aa28bbd6323e4dfb3ac43e",
|
||||
"id": "62aa28fb651bf14efa2dbb16",
|
||||
"title": "Step 170"
|
||||
},
|
||||
{
|
||||
"id": "62aa28fb651bf14efa2dbb16",
|
||||
"id": "62aa2943669c9d5026af6985",
|
||||
"title": "Step 171"
|
||||
},
|
||||
{
|
||||
"id": "62aa2943669c9d5026af6985",
|
||||
"id": "62aa2999ec27ec516655eba6",
|
||||
"title": "Step 172"
|
||||
},
|
||||
{
|
||||
"id": "62aa2999ec27ec516655eba6",
|
||||
"id": "62aa29d8f8f88152c91350ca",
|
||||
"title": "Step 173"
|
||||
},
|
||||
{
|
||||
"id": "62aa29d8f8f88152c91350ca",
|
||||
"id": "62aa2aec2f09d454253aad6c",
|
||||
"title": "Step 174"
|
||||
},
|
||||
{
|
||||
"id": "62aa2aec2f09d454253aad6c",
|
||||
"title": "Step 175"
|
||||
},
|
||||
{
|
||||
"id": "62aa2ba9cd881355a6f0a5a8",
|
||||
"title": "Step 176"
|
||||
"title": "Step 175"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,364 +0,0 @@
|
||||
---
|
||||
id: 62a8f2bc37675e77d5835235
|
||||
title: Step 140
|
||||
challengeType: 0
|
||||
dashedName: step-140
|
||||
---
|
||||
|
||||
# --description--
|
||||
|
||||
JavaScript has a conditional operator called the <dfn>ternary operator</dfn>. This can be used as a one-line `if-else` statement. The syntax is: `condition ? true : false`.
|
||||
|
||||
Here is an example of an `if-else` statement changed to a ternary:
|
||||
|
||||
```js
|
||||
if (num > 5) {
|
||||
bigger()
|
||||
} else {
|
||||
smaller()
|
||||
}
|
||||
|
||||
num > 5 ? bigger() : smaller();
|
||||
```
|
||||
|
||||
Change your new `if-else` statement to a ternary.
|
||||
|
||||
# --hints--
|
||||
|
||||
You should remove the `if` and `else` from your `else if` block.
|
||||
|
||||
```js
|
||||
const block = attack.toString().split("else if");
|
||||
assert.notMatch(block[1], /if/);
|
||||
assert.notMatch(block[1], /else/);
|
||||
```
|
||||
|
||||
You should check if `fighting` is equal to `2`.
|
||||
|
||||
```js
|
||||
const block = attack.toString().split("else if");
|
||||
assert.match(block[1], /fighting\s*===\s*2/);
|
||||
```
|
||||
|
||||
Using the ternary syntax, you should call `winGame` if `fighting` is equal to `2`.
|
||||
|
||||
```js
|
||||
const block = attack.toString().split("else if");
|
||||
assert.match(block[1], /fighting\s*===\s*2\s*\?\s*winGame\(\)/);
|
||||
```
|
||||
|
||||
Using the ternary syntax, you should call `defeatMonster` if `fighting` is not equal to `2`.
|
||||
|
||||
```js
|
||||
const block = attack.toString().split("else if");
|
||||
assert.match(block[1], /fighting\s*===\s*2\s*\?\s*winGame\(\)\s*\:\s*defeatMonster\(\)/);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```html
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<link rel="stylesheet" href="./styles.css">
|
||||
<title>RPG - Dragon Repeller</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="game">
|
||||
<div id="stats">
|
||||
<span class="stat">XP: <strong><span id="xpText">0</span></strong></span>
|
||||
<span class="stat">Health: <strong><span id="healthText">100</span></strong></span>
|
||||
<span class="stat">Gold: <strong><span id="goldText">50</span></strong></span>
|
||||
</div>
|
||||
<div id="controls">
|
||||
<button id="button1">Go to store</button>
|
||||
<button id="button2">Go to cave</button>
|
||||
<button id="button3">Fight dragon</button>
|
||||
</div>
|
||||
<div id="monsterStats">
|
||||
<span class="stat">Monster Name: <strong><span id="monsterName"></span></strong></span>
|
||||
<span class="stat">Health: <strong><span id="monsterHealth"></span></strong></span>
|
||||
</div>
|
||||
<div id="text">
|
||||
Welcome to Dragon Repeller. You must defeat the dragon that is preventing people from leaving the town. You are in the town square. Where do you want to go? Use the buttons above.
|
||||
</div>
|
||||
</div>
|
||||
<script src="./script.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
```css
|
||||
body {
|
||||
background-color: #0a0a23;
|
||||
}
|
||||
|
||||
#text {
|
||||
background-color: #0a0a23;
|
||||
color: #ffffff;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
#game {
|
||||
max-width: 500px;
|
||||
max-height: 400px;
|
||||
background-color: #ffffff;
|
||||
color: #ffffff;
|
||||
margin: 30px auto 0px;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
#controls,
|
||||
#stats {
|
||||
border: 1px solid #0a0a23;
|
||||
padding: 5px;
|
||||
color: #0a0a23;
|
||||
}
|
||||
|
||||
#monsterStats {
|
||||
display: none;
|
||||
border: 1px solid #0a0a23;
|
||||
padding: 5px;
|
||||
color: #ffffff;
|
||||
background-color: #c70d0d;
|
||||
}
|
||||
|
||||
.stat {
|
||||
padding-right: 10px;
|
||||
}
|
||||
|
||||
button {
|
||||
cursor: pointer;
|
||||
color: #0a0a23;
|
||||
background-color: #feac32;
|
||||
background-image: linear-gradient(#fecc4c, #ffac33);
|
||||
border: 3px solid #feac32;
|
||||
}
|
||||
```
|
||||
|
||||
```js
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
const button1 = document.querySelector('#button1');
|
||||
const button2 = document.querySelector("#button2");
|
||||
const button3 = document.querySelector("#button3");
|
||||
const text = document.querySelector("#text");
|
||||
const xpText = document.querySelector("#xpText");
|
||||
const healthText = document.querySelector("#healthText");
|
||||
const goldText = document.querySelector("#goldText");
|
||||
const monsterStats = document.querySelector("#monsterStats");
|
||||
const monsterName = 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 }
|
||||
];
|
||||
const monsters = [
|
||||
{
|
||||
name: "slime",
|
||||
level: 2,
|
||||
health: 15
|
||||
},
|
||||
{
|
||||
name: "fanged beast",
|
||||
level: 8,
|
||||
health: 60
|
||||
},
|
||||
{
|
||||
name: "dragon",
|
||||
level: 20,
|
||||
health: 300
|
||||
}
|
||||
]
|
||||
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: "lose",
|
||||
"button text": ["REPLAY?", "REPLAY?", "REPLAY?"],
|
||||
"button functions": [restart, restart, restart],
|
||||
text: "You die. ☠️"
|
||||
}
|
||||
];
|
||||
|
||||
// initialize buttons
|
||||
button1.onclick = goStore;
|
||||
button2.onclick = goCave;
|
||||
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;
|
||||
}
|
||||
|
||||
function goTown() {
|
||||
update(locations[0]);
|
||||
}
|
||||
|
||||
function goStore() {
|
||||
update(locations[1]);
|
||||
}
|
||||
|
||||
function goCave() {
|
||||
update(locations[2]);
|
||||
}
|
||||
|
||||
function buyHealth() {
|
||||
if (gold >= 10) {
|
||||
gold -= 10;
|
||||
health += 10;
|
||||
goldText.innerText = gold;
|
||||
healthText.innerText = health;
|
||||
} else {
|
||||
text.innerText = "You do not have enough gold to buy health.";
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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!";
|
||||
}
|
||||
}
|
||||
|
||||
function fightSlime() {
|
||||
fighting = 0;
|
||||
goFight();
|
||||
}
|
||||
|
||||
function fightBeast() {
|
||||
fighting = 1;
|
||||
goFight();
|
||||
}
|
||||
|
||||
function fightDragon() {
|
||||
fighting = 2;
|
||||
goFight();
|
||||
}
|
||||
|
||||
function goFight() {
|
||||
update(locations[3]);
|
||||
monsterHealth = monsters[fighting].health;
|
||||
monsterStats.style.display = "block";
|
||||
monsterName.innerText = monsters[fighting].name;
|
||||
monsterHealthText.innerText = monsterHealth;
|
||||
}
|
||||
|
||||
--fcc-editable-region--
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
--fcc-editable-region--
|
||||
|
||||
function dodge() {
|
||||
text.innerText = "You dodge the attack from the " + monsters[fighting].name;
|
||||
}
|
||||
|
||||
function defeatMonster() {
|
||||
gold += Math.floor(monsters[fighting].level * 6.7);
|
||||
xp += monsters[fighting].level;
|
||||
goldText.innerText = gold;
|
||||
xpText.innerText = xp;
|
||||
update(locations[4]);
|
||||
}
|
||||
|
||||
function lose() {
|
||||
update(locations[5]);
|
||||
}
|
||||
|
||||
function restart() {
|
||||
xp = 0;
|
||||
health = 100;
|
||||
gold = 50;
|
||||
currentWeapon = 0;
|
||||
inventory = ["stick"];
|
||||
goldText.innerText = gold;
|
||||
healthText.innerText = health;
|
||||
xpText.innerText = xp;
|
||||
goTown();
|
||||
}
|
||||
```
|
||||
@@ -1,8 +1,8 @@
|
||||
---
|
||||
id: 62a8f35bde1750791f58773f
|
||||
title: Step 141
|
||||
title: Step 140
|
||||
challengeType: 0
|
||||
dashedName: step-141
|
||||
dashedName: step-140
|
||||
---
|
||||
|
||||
# --description--
|
||||
@@ -293,7 +293,11 @@ function attack() {
|
||||
if (health <= 0) {
|
||||
lose();
|
||||
} else if (monsterHealth <= 0) {
|
||||
fighting === 2 ? winGame() : defeatMonster();
|
||||
if (fighting === 2) {
|
||||
winGame();
|
||||
} else {
|
||||
defeatMonster();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
---
|
||||
id: 62a94114ce0b8918b487390f
|
||||
title: Step 142
|
||||
title: Step 141
|
||||
challengeType: 0
|
||||
dashedName: step-142
|
||||
dashedName: step-141
|
||||
---
|
||||
|
||||
# --description--
|
||||
@@ -319,7 +319,11 @@ function attack() {
|
||||
if (health <= 0) {
|
||||
lose();
|
||||
} else if (monsterHealth <= 0) {
|
||||
fighting === 2 ? winGame() : defeatMonster();
|
||||
if (fighting === 2) {
|
||||
winGame();
|
||||
} else {
|
||||
defeatMonster();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
---
|
||||
id: 62aa1cea594f152ba626b872
|
||||
title: Step 143
|
||||
title: Step 142
|
||||
challengeType: 0
|
||||
dashedName: step-143
|
||||
dashedName: step-142
|
||||
---
|
||||
|
||||
# --description--
|
||||
@@ -296,7 +296,11 @@ function attack() {
|
||||
if (health <= 0) {
|
||||
lose();
|
||||
} else if (monsterHealth <= 0) {
|
||||
fighting === 2 ? winGame() : defeatMonster();
|
||||
if (fighting === 2) {
|
||||
winGame();
|
||||
} else {
|
||||
defeatMonster();
|
||||
}
|
||||
}
|
||||
}
|
||||
--fcc-editable-region--
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
---
|
||||
id: 62aa1d6736ba262cfa74344b
|
||||
title: Step 144
|
||||
title: Step 143
|
||||
challengeType: 0
|
||||
dashedName: step-144
|
||||
dashedName: step-143
|
||||
---
|
||||
|
||||
# --description--
|
||||
@@ -299,7 +299,11 @@ function attack() {
|
||||
if (health <= 0) {
|
||||
lose();
|
||||
} else if (monsterHealth <= 0) {
|
||||
fighting === 2 ? winGame() : defeatMonster();
|
||||
if (fighting === 2) {
|
||||
winGame();
|
||||
} else {
|
||||
defeatMonster();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
---
|
||||
id: 62aa1d9f535e102e4663e7a6
|
||||
title: Step 145
|
||||
title: Step 144
|
||||
challengeType: 0
|
||||
dashedName: step-145
|
||||
dashedName: step-144
|
||||
---
|
||||
|
||||
# --description--
|
||||
@@ -307,7 +307,11 @@ function attack() {
|
||||
if (health <= 0) {
|
||||
lose();
|
||||
} else if (monsterHealth <= 0) {
|
||||
fighting === 2 ? winGame() : defeatMonster();
|
||||
if (fighting === 2) {
|
||||
winGame();
|
||||
} else {
|
||||
defeatMonster();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
---
|
||||
id: 62aa1e3c7c3d552fb04f0f18
|
||||
title: Step 146
|
||||
title: Step 145
|
||||
challengeType: 0
|
||||
dashedName: step-146
|
||||
dashedName: step-145
|
||||
---
|
||||
|
||||
# --description--
|
||||
@@ -293,7 +293,11 @@ function attack() {
|
||||
if (health <= 0) {
|
||||
lose();
|
||||
} else if (monsterHealth <= 0) {
|
||||
fighting === 2 ? winGame() : defeatMonster();
|
||||
if (fighting === 2) {
|
||||
winGame();
|
||||
} else {
|
||||
defeatMonster();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
---
|
||||
id: 62aa1e8ccd579330e097ce44
|
||||
title: Step 147
|
||||
title: Step 146
|
||||
challengeType: 0
|
||||
dashedName: step-147
|
||||
dashedName: step-146
|
||||
---
|
||||
|
||||
# --description--
|
||||
@@ -302,7 +302,11 @@ function attack() {
|
||||
if (health <= 0) {
|
||||
lose();
|
||||
} else if (monsterHealth <= 0) {
|
||||
fighting === 2 ? winGame() : defeatMonster();
|
||||
if (fighting === 2) {
|
||||
winGame();
|
||||
} else {
|
||||
defeatMonster();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,22 +1,30 @@
|
||||
---
|
||||
id: 62aa1eec891ed731db227a36
|
||||
title: Step 148
|
||||
title: Step 147
|
||||
challengeType: 0
|
||||
dashedName: step-148
|
||||
dashedName: step-147
|
||||
---
|
||||
|
||||
# --description--
|
||||
|
||||
If you play the game in its current state you might notice a bug. If your `xp` is high enough, the `getMonsterAttackValue` function will return a negative number, which will actually add to your total health when fighting a monster!
|
||||
If you play the game in its current state you might notice a bug. If your `xp` is high enough, the `getMonsterAttackValue` function will return a negative number, which will actually add to your total health when fighting a monster! You can fix this issue by using a <dfn>ternary operator</dfn> to ensure negative values are not returned.
|
||||
|
||||
In `getMonsterAttackValue`, change `return hit` to a ternary operator that returns `hit` if `hit` is greater than `0`, or returns `0` if it is not.
|
||||
The `ternary operator` is a conditional operator and can be used as a one-line `if-else` statement. The syntax is: `condition ? expressionIfTrue : expressionIfFalse`.
|
||||
|
||||
Here is an example of returning a value based on `condition` with a ternary:
|
||||
Here is an example of returning a value using an `if-else` statement and a refactored example using a ternary operator:
|
||||
|
||||
```js
|
||||
return condition ? true : false;
|
||||
if (num > 5) {
|
||||
return 'num is greater than 5';
|
||||
} else {
|
||||
return 'num is smaller than or equal to 5';
|
||||
}
|
||||
|
||||
return num > 5 ? 'num is greater than 5' : 'num is smaller than or equal to 5';
|
||||
```
|
||||
|
||||
In `getMonsterAttackValue`, change `return hit` to a ternary operator that returns `hit` if `hit` is greater than `0`, or returns `0` if it is not.
|
||||
|
||||
# --hints--
|
||||
|
||||
You should use a ternary to change the `return` value if `hit` is greater than `0`.
|
||||
@@ -313,7 +321,11 @@ function attack() {
|
||||
if (health <= 0) {
|
||||
lose();
|
||||
} else if (monsterHealth <= 0) {
|
||||
fighting === 2 ? winGame() : defeatMonster();
|
||||
if (fighting === 2) {
|
||||
winGame();
|
||||
} else {
|
||||
defeatMonster();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
---
|
||||
id: 62aa1fed3d4e873366ff3131
|
||||
title: Step 149
|
||||
title: Step 148
|
||||
challengeType: 0
|
||||
dashedName: step-149
|
||||
dashedName: step-148
|
||||
---
|
||||
|
||||
# --description--
|
||||
@@ -295,7 +295,11 @@ function attack() {
|
||||
if (health <= 0) {
|
||||
lose();
|
||||
} else if (monsterHealth <= 0) {
|
||||
fighting === 2 ? winGame() : defeatMonster();
|
||||
if (fighting === 2) {
|
||||
winGame();
|
||||
} else {
|
||||
defeatMonster();
|
||||
}
|
||||
}
|
||||
}
|
||||
--fcc-editable-region--
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
---
|
||||
id: 62aa204c1e1d33348ff09944
|
||||
title: Step 150
|
||||
title: Step 149
|
||||
challengeType: 0
|
||||
dashedName: step-150
|
||||
dashedName: step-149
|
||||
---
|
||||
|
||||
# --description--
|
||||
@@ -297,7 +297,11 @@ function attack() {
|
||||
if (health <= 0) {
|
||||
lose();
|
||||
} else if (monsterHealth <= 0) {
|
||||
fighting === 2 ? winGame() : defeatMonster();
|
||||
if (fighting === 2) {
|
||||
winGame();
|
||||
} else {
|
||||
defeatMonster();
|
||||
}
|
||||
}
|
||||
}
|
||||
--fcc-editable-region--
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
---
|
||||
id: 62aa20e9cf1be9358f5aceae
|
||||
title: Step 151
|
||||
title: Step 150
|
||||
challengeType: 0
|
||||
dashedName: step-151
|
||||
dashedName: step-150
|
||||
---
|
||||
|
||||
# --description--
|
||||
@@ -302,7 +302,11 @@ function attack() {
|
||||
if (health <= 0) {
|
||||
lose();
|
||||
} else if (monsterHealth <= 0) {
|
||||
fighting === 2 ? winGame() : defeatMonster();
|
||||
if (fighting === 2) {
|
||||
winGame();
|
||||
} else {
|
||||
defeatMonster();
|
||||
}
|
||||
}
|
||||
}
|
||||
--fcc-editable-region--
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
---
|
||||
id: 62aa2136fc49b836dfedb959
|
||||
title: Step 152
|
||||
title: Step 151
|
||||
challengeType: 0
|
||||
dashedName: step-152
|
||||
dashedName: step-151
|
||||
---
|
||||
|
||||
# --description--
|
||||
@@ -303,7 +303,11 @@ function attack() {
|
||||
if (health <= 0) {
|
||||
lose();
|
||||
} else if (monsterHealth <= 0) {
|
||||
fighting === 2 ? winGame() : defeatMonster();
|
||||
if (fighting === 2) {
|
||||
winGame();
|
||||
} else {
|
||||
defeatMonster();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
---
|
||||
id: 62aa21971e3b743844849985
|
||||
title: Step 153
|
||||
title: Step 152
|
||||
challengeType: 0
|
||||
dashedName: step-153
|
||||
dashedName: step-152
|
||||
---
|
||||
|
||||
# --description--
|
||||
@@ -315,7 +315,11 @@ function attack() {
|
||||
if (health <= 0) {
|
||||
lose();
|
||||
} else if (monsterHealth <= 0) {
|
||||
fighting === 2 ? winGame() : defeatMonster();
|
||||
if (fighting === 2) {
|
||||
winGame();
|
||||
} else {
|
||||
defeatMonster();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
---
|
||||
id: 62aa21ea8d9d9f396b95dd87
|
||||
title: Step 154
|
||||
title: Step 153
|
||||
challengeType: 0
|
||||
dashedName: step-154
|
||||
dashedName: step-153
|
||||
---
|
||||
|
||||
# --description--
|
||||
@@ -15,7 +15,7 @@ You should add an `if` statement to your `attack` function.
|
||||
|
||||
```js
|
||||
const ifs = attack.toString().match(/if/g);
|
||||
assert.lengthOf(ifs, 4);
|
||||
assert.lengthOf(ifs, 5);
|
||||
```
|
||||
|
||||
Your new `if` statement should check `Math.random() <= .1`.
|
||||
@@ -305,7 +305,11 @@ function attack() {
|
||||
if (health <= 0) {
|
||||
lose();
|
||||
} else if (monsterHealth <= 0) {
|
||||
fighting === 2 ? winGame() : defeatMonster();
|
||||
if (fighting === 2) {
|
||||
winGame();
|
||||
} else {
|
||||
defeatMonster();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
---
|
||||
id: 62aa226207f33d3ad4c6f546
|
||||
title: Step 155
|
||||
title: Step 154
|
||||
challengeType: 0
|
||||
dashedName: step-155
|
||||
dashedName: step-154
|
||||
---
|
||||
|
||||
# --description--
|
||||
@@ -324,7 +324,11 @@ function attack() {
|
||||
if (health <= 0) {
|
||||
lose();
|
||||
} else if (monsterHealth <= 0) {
|
||||
fighting === 2 ? winGame() : defeatMonster();
|
||||
if (fighting === 2) {
|
||||
winGame();
|
||||
} else {
|
||||
defeatMonster();
|
||||
}
|
||||
}
|
||||
if (Math.random() <= .1) {
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
---
|
||||
id: 62aa22aba186563bcbf2c395
|
||||
title: Step 156
|
||||
title: Step 155
|
||||
challengeType: 0
|
||||
dashedName: step-156
|
||||
dashedName: step-155
|
||||
---
|
||||
|
||||
# --description--
|
||||
@@ -306,7 +306,11 @@ function attack() {
|
||||
if (health <= 0) {
|
||||
lose();
|
||||
} else if (monsterHealth <= 0) {
|
||||
fighting === 2 ? winGame() : defeatMonster();
|
||||
if (fighting === 2) {
|
||||
winGame();
|
||||
} else {
|
||||
defeatMonster();
|
||||
}
|
||||
}
|
||||
if (Math.random() <= .1) {
|
||||
text.innerText += " Your " + inventory.pop() + " breaks.";
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
---
|
||||
id: 62aa234322d4ad3e8bce42cc
|
||||
title: Step 157
|
||||
title: Step 156
|
||||
challengeType: 0
|
||||
dashedName: step-157
|
||||
dashedName: step-156
|
||||
---
|
||||
|
||||
# --description--
|
||||
@@ -320,7 +320,11 @@ function attack() {
|
||||
if (health <= 0) {
|
||||
lose();
|
||||
} else if (monsterHealth <= 0) {
|
||||
fighting === 2 ? winGame() : defeatMonster();
|
||||
if (fighting === 2) {
|
||||
winGame();
|
||||
} else {
|
||||
defeatMonster();
|
||||
}
|
||||
}
|
||||
if (Math.random() <= .1) {
|
||||
text.innerText += " Your " + inventory.pop() + " breaks.";
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
---
|
||||
id: 62aa2469c77b363fdb4f0e06
|
||||
title: Step 158
|
||||
title: Step 157
|
||||
challengeType: 0
|
||||
dashedName: step-158
|
||||
dashedName: step-157
|
||||
---
|
||||
|
||||
# --description--
|
||||
@@ -311,7 +311,11 @@ function attack() {
|
||||
if (health <= 0) {
|
||||
lose();
|
||||
} else if (monsterHealth <= 0) {
|
||||
fighting === 2 ? winGame() : defeatMonster();
|
||||
if (fighting === 2) {
|
||||
winGame();
|
||||
} else {
|
||||
defeatMonster();
|
||||
}
|
||||
}
|
||||
if (Math.random() <= .1 && inventory.length !== 1) {
|
||||
text.innerText += " Your " + inventory.pop() + " breaks.";
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
---
|
||||
id: 62aa252c3b1073415ba2b898
|
||||
title: Step 159
|
||||
title: Step 158
|
||||
challengeType: 0
|
||||
dashedName: step-159
|
||||
dashedName: step-158
|
||||
---
|
||||
|
||||
# --description--
|
||||
@@ -303,7 +303,11 @@ function attack() {
|
||||
if (health <= 0) {
|
||||
lose();
|
||||
} else if (monsterHealth <= 0) {
|
||||
fighting === 2 ? winGame() : defeatMonster();
|
||||
if (fighting === 2) {
|
||||
winGame();
|
||||
} else {
|
||||
defeatMonster();
|
||||
}
|
||||
}
|
||||
if (Math.random() <= .1 && inventory.length !== 1) {
|
||||
text.innerText += " Your " + inventory.pop() + " breaks.";
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
---
|
||||
id: 62aa258da314ef42ba0a1858
|
||||
title: Step 160
|
||||
title: Step 159
|
||||
challengeType: 0
|
||||
dashedName: step-160
|
||||
dashedName: step-159
|
||||
---
|
||||
|
||||
# --description--
|
||||
@@ -329,7 +329,11 @@ function attack() {
|
||||
if (health <= 0) {
|
||||
lose();
|
||||
} else if (monsterHealth <= 0) {
|
||||
fighting === 2 ? winGame() : defeatMonster();
|
||||
if (fighting === 2) {
|
||||
winGame();
|
||||
} else {
|
||||
defeatMonster();
|
||||
}
|
||||
}
|
||||
if (Math.random() <= .1 && inventory.length !== 1) {
|
||||
text.innerText += " Your " + inventory.pop() + " breaks.";
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
---
|
||||
id: 62aa25fcb5837d43b4d9873d
|
||||
title: Step 161
|
||||
title: Step 160
|
||||
challengeType: 0
|
||||
dashedName: step-161
|
||||
dashedName: step-160
|
||||
---
|
||||
|
||||
# --description--
|
||||
@@ -330,7 +330,11 @@ function attack() {
|
||||
if (health <= 0) {
|
||||
lose();
|
||||
} else if (monsterHealth <= 0) {
|
||||
fighting === 2 ? winGame() : defeatMonster();
|
||||
if (fighting === 2) {
|
||||
winGame();
|
||||
} else {
|
||||
defeatMonster();
|
||||
}
|
||||
}
|
||||
if (Math.random() <= .1 && inventory.length !== 1) {
|
||||
text.innerText += " Your " + inventory.pop() + " breaks.";
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
---
|
||||
id: 62aa2626c3c10244b94c787b
|
||||
title: Step 162
|
||||
title: Step 161
|
||||
challengeType: 0
|
||||
dashedName: step-162
|
||||
dashedName: step-161
|
||||
---
|
||||
|
||||
# --description--
|
||||
@@ -303,7 +303,11 @@ function attack() {
|
||||
if (health <= 0) {
|
||||
lose();
|
||||
} else if (monsterHealth <= 0) {
|
||||
fighting === 2 ? winGame() : defeatMonster();
|
||||
if (fighting === 2) {
|
||||
winGame();
|
||||
} else {
|
||||
defeatMonster();
|
||||
}
|
||||
}
|
||||
if (Math.random() <= .1 && inventory.length !== 1) {
|
||||
text.innerText += " Your " + inventory.pop() + " breaks.";
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
---
|
||||
id: 62aa264d23cdaa45a20efada
|
||||
title: Step 163
|
||||
title: Step 162
|
||||
challengeType: 0
|
||||
dashedName: step-163
|
||||
dashedName: step-162
|
||||
---
|
||||
|
||||
# --description--
|
||||
@@ -319,7 +319,11 @@ function attack() {
|
||||
if (health <= 0) {
|
||||
lose();
|
||||
} else if (monsterHealth <= 0) {
|
||||
fighting === 2 ? winGame() : defeatMonster();
|
||||
if (fighting === 2) {
|
||||
winGame();
|
||||
} else {
|
||||
defeatMonster();
|
||||
}
|
||||
}
|
||||
if (Math.random() <= .1 && inventory.length !== 1) {
|
||||
text.innerText += " Your " + inventory.pop() + " breaks.";
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
---
|
||||
id: 62aa26cca3cd3d46c431e73b
|
||||
title: Step 164
|
||||
title: Step 163
|
||||
challengeType: 0
|
||||
dashedName: step-164
|
||||
dashedName: step-163
|
||||
---
|
||||
|
||||
# --description--
|
||||
@@ -315,7 +315,11 @@ function attack() {
|
||||
if (health <= 0) {
|
||||
lose();
|
||||
} else if (monsterHealth <= 0) {
|
||||
fighting === 2 ? winGame() : defeatMonster();
|
||||
if (fighting === 2) {
|
||||
winGame();
|
||||
} else {
|
||||
defeatMonster();
|
||||
}
|
||||
}
|
||||
if (Math.random() <= .1 && inventory.length !== 1) {
|
||||
text.innerText += " Your " + inventory.pop() + " breaks.";
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
---
|
||||
id: 62aa27227399d647e1c37a3c
|
||||
title: Step 165
|
||||
title: Step 164
|
||||
challengeType: 0
|
||||
dashedName: step-165
|
||||
dashedName: step-164
|
||||
---
|
||||
|
||||
# --description--
|
||||
@@ -315,7 +315,11 @@ function attack() {
|
||||
if (health <= 0) {
|
||||
lose();
|
||||
} else if (monsterHealth <= 0) {
|
||||
fighting === 2 ? winGame() : defeatMonster();
|
||||
if (fighting === 2) {
|
||||
winGame();
|
||||
} else {
|
||||
defeatMonster();
|
||||
}
|
||||
}
|
||||
if (Math.random() <= .1 && inventory.length !== 1) {
|
||||
text.innerText += " Your " + inventory.pop() + " breaks.";
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
---
|
||||
id: 62aa27560def7048d7b4a095
|
||||
title: Step 166
|
||||
title: Step 165
|
||||
challengeType: 0
|
||||
dashedName: step-166
|
||||
dashedName: step-165
|
||||
---
|
||||
|
||||
# --description--
|
||||
@@ -303,7 +303,11 @@ function attack() {
|
||||
if (health <= 0) {
|
||||
lose();
|
||||
} else if (monsterHealth <= 0) {
|
||||
fighting === 2 ? winGame() : defeatMonster();
|
||||
if (fighting === 2) {
|
||||
winGame();
|
||||
} else {
|
||||
defeatMonster();
|
||||
}
|
||||
}
|
||||
if (Math.random() <= .1 && inventory.length !== 1) {
|
||||
text.innerText += " Your " + inventory.pop() + " breaks.";
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
---
|
||||
id: 62aa27c40ca6f04ab8be5fac
|
||||
title: Step 167
|
||||
title: Step 166
|
||||
challengeType: 0
|
||||
dashedName: step-167
|
||||
dashedName: step-166
|
||||
---
|
||||
|
||||
# --description--
|
||||
@@ -309,7 +309,11 @@ function attack() {
|
||||
if (health <= 0) {
|
||||
lose();
|
||||
} else if (monsterHealth <= 0) {
|
||||
fighting === 2 ? winGame() : defeatMonster();
|
||||
if (fighting === 2) {
|
||||
winGame();
|
||||
} else {
|
||||
defeatMonster();
|
||||
}
|
||||
}
|
||||
if (Math.random() <= .1 && inventory.length !== 1) {
|
||||
text.innerText += " Your " + inventory.pop() + " breaks.";
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
---
|
||||
id: 62aa28032d863d4bd8058799
|
||||
title: Step 168
|
||||
title: Step 167
|
||||
challengeType: 0
|
||||
dashedName: step-168
|
||||
dashedName: step-167
|
||||
---
|
||||
|
||||
# --description--
|
||||
@@ -307,7 +307,11 @@ function attack() {
|
||||
if (health <= 0) {
|
||||
lose();
|
||||
} else if (monsterHealth <= 0) {
|
||||
fighting === 2 ? winGame() : defeatMonster();
|
||||
if (fighting === 2) {
|
||||
winGame();
|
||||
} else {
|
||||
defeatMonster();
|
||||
}
|
||||
}
|
||||
if (Math.random() <= .1 && inventory.length !== 1) {
|
||||
text.innerText += " Your " + inventory.pop() + " breaks.";
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
---
|
||||
id: 62aa287434dc284cea01157c
|
||||
title: Step 169
|
||||
title: Step 168
|
||||
challengeType: 0
|
||||
dashedName: step-169
|
||||
dashedName: step-168
|
||||
---
|
||||
|
||||
# --description--
|
||||
@@ -305,7 +305,11 @@ function attack() {
|
||||
if (health <= 0) {
|
||||
lose();
|
||||
} else if (monsterHealth <= 0) {
|
||||
fighting === 2 ? winGame() : defeatMonster();
|
||||
if (fighting === 2) {
|
||||
winGame();
|
||||
} else {
|
||||
defeatMonster();
|
||||
}
|
||||
}
|
||||
if (Math.random() <= .1 && inventory.length !== 1) {
|
||||
text.innerText += " Your " + inventory.pop() + " breaks.";
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
---
|
||||
id: 62aa28bbd6323e4dfb3ac43e
|
||||
title: Step 170
|
||||
title: Step 169
|
||||
challengeType: 0
|
||||
dashedName: step-170
|
||||
dashedName: step-169
|
||||
---
|
||||
|
||||
# --description--
|
||||
@@ -305,7 +305,11 @@ function attack() {
|
||||
if (health <= 0) {
|
||||
lose();
|
||||
} else if (monsterHealth <= 0) {
|
||||
fighting === 2 ? winGame() : defeatMonster();
|
||||
if (fighting === 2) {
|
||||
winGame();
|
||||
} else {
|
||||
defeatMonster();
|
||||
}
|
||||
}
|
||||
if (Math.random() <= .1 && inventory.length !== 1) {
|
||||
text.innerText += " Your " + inventory.pop() + " breaks.";
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
---
|
||||
id: 62aa28fb651bf14efa2dbb16
|
||||
title: Step 171
|
||||
title: Step 170
|
||||
challengeType: 0
|
||||
dashedName: step-171
|
||||
dashedName: step-170
|
||||
---
|
||||
|
||||
# --description--
|
||||
@@ -322,7 +322,11 @@ function attack() {
|
||||
if (health <= 0) {
|
||||
lose();
|
||||
} else if (monsterHealth <= 0) {
|
||||
fighting === 2 ? winGame() : defeatMonster();
|
||||
if (fighting === 2) {
|
||||
winGame();
|
||||
} else {
|
||||
defeatMonster();
|
||||
}
|
||||
}
|
||||
if (Math.random() <= .1 && inventory.length !== 1) {
|
||||
text.innerText += " Your " + inventory.pop() + " breaks.";
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
---
|
||||
id: 62aa2943669c9d5026af6985
|
||||
title: Step 172
|
||||
title: Step 171
|
||||
challengeType: 0
|
||||
dashedName: step-172
|
||||
dashedName: step-171
|
||||
---
|
||||
|
||||
# --description--
|
||||
@@ -322,7 +322,11 @@ function attack() {
|
||||
if (health <= 0) {
|
||||
lose();
|
||||
} else if (monsterHealth <= 0) {
|
||||
fighting === 2 ? winGame() : defeatMonster();
|
||||
if (fighting === 2) {
|
||||
winGame();
|
||||
} else {
|
||||
defeatMonster();
|
||||
}
|
||||
}
|
||||
if (Math.random() <= .1 && inventory.length !== 1) {
|
||||
text.innerText += " Your " + inventory.pop() + " breaks.";
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
---
|
||||
id: 62aa2999ec27ec516655eba6
|
||||
title: Step 173
|
||||
title: Step 172
|
||||
challengeType: 0
|
||||
dashedName: step-173
|
||||
dashedName: step-172
|
||||
---
|
||||
|
||||
# --description--
|
||||
@@ -315,7 +315,11 @@ function attack() {
|
||||
if (health <= 0) {
|
||||
lose();
|
||||
} else if (monsterHealth <= 0) {
|
||||
fighting === 2 ? winGame() : defeatMonster();
|
||||
if (fighting === 2) {
|
||||
winGame();
|
||||
} else {
|
||||
defeatMonster();
|
||||
}
|
||||
}
|
||||
if (Math.random() <= .1 && inventory.length !== 1) {
|
||||
text.innerText += " Your " + inventory.pop() + " breaks.";
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
---
|
||||
id: 62aa29d8f8f88152c91350ca
|
||||
title: Step 174
|
||||
title: Step 173
|
||||
challengeType: 0
|
||||
dashedName: step-174
|
||||
dashedName: step-173
|
||||
---
|
||||
|
||||
# --description--
|
||||
@@ -321,7 +321,11 @@ function attack() {
|
||||
if (health <= 0) {
|
||||
lose();
|
||||
} else if (monsterHealth <= 0) {
|
||||
fighting === 2 ? winGame() : defeatMonster();
|
||||
if (fighting === 2) {
|
||||
winGame();
|
||||
} else {
|
||||
defeatMonster();
|
||||
}
|
||||
}
|
||||
if (Math.random() <= .1 && inventory.length !== 1) {
|
||||
text.innerText += " Your " + inventory.pop() + " breaks.";
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
---
|
||||
id: 62aa2aec2f09d454253aad6c
|
||||
title: Step 175
|
||||
title: Step 174
|
||||
challengeType: 0
|
||||
dashedName: step-175
|
||||
dashedName: step-174
|
||||
---
|
||||
|
||||
# --description--
|
||||
@@ -316,7 +316,11 @@ function attack() {
|
||||
if (health <= 0) {
|
||||
lose();
|
||||
} else if (monsterHealth <= 0) {
|
||||
fighting === 2 ? winGame() : defeatMonster();
|
||||
if (fighting === 2) {
|
||||
winGame();
|
||||
} else {
|
||||
defeatMonster();
|
||||
}
|
||||
}
|
||||
if (Math.random() <= .1 && inventory.length !== 1) {
|
||||
text.innerText += " Your " + inventory.pop() + " breaks.";
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
---
|
||||
id: 62aa2ba9cd881355a6f0a5a8
|
||||
title: Step 176
|
||||
title: Step 175
|
||||
challengeType: 0
|
||||
dashedName: step-176
|
||||
dashedName: step-175
|
||||
---
|
||||
|
||||
# --description--
|
||||
@@ -307,7 +307,11 @@ function attack() {
|
||||
if (health <= 0) {
|
||||
lose();
|
||||
} else if (monsterHealth <= 0) {
|
||||
fighting === 2 ? winGame() : defeatMonster();
|
||||
if (fighting === 2) {
|
||||
winGame();
|
||||
} else {
|
||||
defeatMonster();
|
||||
}
|
||||
}
|
||||
if (Math.random() <= .1 && inventory.length !== 1) {
|
||||
text.innerText += " Your " + inventory.pop() + " breaks.";
|
||||
@@ -677,7 +681,11 @@ function attack() {
|
||||
if (health <= 0) {
|
||||
lose();
|
||||
} else if (monsterHealth <= 0) {
|
||||
fighting === 2 ? winGame() : defeatMonster();
|
||||
if (fighting === 2) {
|
||||
winGame();
|
||||
} else {
|
||||
defeatMonster();
|
||||
}
|
||||
}
|
||||
if (Math.random() <= .1 && inventory.length !== 1) {
|
||||
text.innerText += " Your " + inventory.pop() + " breaks.";
|
||||
|
||||
Reference in New Issue
Block a user