chore(curriculum): add steps to test buyWeapon function in RPG project (#54573)

Co-authored-by: Naomi <nhcarrigan@gmail.com>
This commit is contained in:
Jessica Wilkins
2024-04-30 06:43:09 -07:00
committed by GitHub
parent ae60c0ae2d
commit a534e4ff75
79 changed files with 698 additions and 233 deletions

View File

@@ -396,308 +396,316 @@
"title": "Step 96"
},
{
"id": "62a8d1c72e8bb13c2074d93c",
"id": "662fbead61552e06d30fc048",
"title": "Step 97"
},
{
"id": "62a8d2146a3e853d0a6e28ca",
"id": "62a8d1c72e8bb13c2074d93c",
"title": "Step 98"
},
{
"id": "62a8d24c97461b3ddb9397c8",
"id": "62a8d2146a3e853d0a6e28ca",
"title": "Step 99"
},
{
"id": "62a8d2e2a073be3edb46116f",
"id": "662fc372da60030ae25b194e",
"title": "Step 100"
},
{
"id": "62a8d31ebbc10e3fe1b28e03",
"id": "62a8d24c97461b3ddb9397c8",
"title": "Step 101"
},
{
"id": "62a8d35660db4040ba292193",
"id": "62a8d2e2a073be3edb46116f",
"title": "Step 102"
},
{
"id": "62a8d382cd075f4169223e14",
"id": "62a8d31ebbc10e3fe1b28e03",
"title": "Step 103"
},
{
"id": "62a8d539dc11cb42b5dd7ec8",
"id": "62a8d35660db4040ba292193",
"title": "Step 104"
},
{
"id": "62a8d61ddfe35744369365b7",
"id": "62a8d382cd075f4169223e14",
"title": "Step 105"
},
{
"id": "62a8d6c7001ebc45350e3d16",
"id": "62a8d539dc11cb42b5dd7ec8",
"title": "Step 106"
},
{
"id": "62a8d7b8ab568b4649998954",
"id": "62a8d61ddfe35744369365b7",
"title": "Step 107"
},
{
"id": "62a8d81f539f004776dd9b1e",
"id": "62a8d6c7001ebc45350e3d16",
"title": "Step 108"
},
{
"id": "62a8dd468debb449b4454086",
"id": "62a8d7b8ab568b4649998954",
"title": "Step 109"
},
{
"id": "62a8dd9cdb16324b04cfd958",
"id": "62a8d81f539f004776dd9b1e",
"title": "Step 110"
},
{
"id": "62a8dfcf7fb1044d2f478fd1",
"id": "62a8dd468debb449b4454086",
"title": "Step 111"
},
{
"id": "62a8e0d1d0110b4ec421489f",
"id": "62a8dd9cdb16324b04cfd958",
"title": "Step 112"
},
{
"id": "62a8e142f7f0bd4fed898de3",
"id": "62a8dfcf7fb1044d2f478fd1",
"title": "Step 113"
},
{
"id": "62a8e1dc897df55108bcb5e8",
"id": "62a8e0d1d0110b4ec421489f",
"title": "Step 114"
},
{
"id": "62a8e21398ad61520edb724f",
"id": "62a8e142f7f0bd4fed898de3",
"title": "Step 115"
},
{
"id": "62a8e24c673b075317cc0b09",
"id": "62a8e1dc897df55108bcb5e8",
"title": "Step 116"
},
{
"id": "62a8e271f8e3d1541f9624ad",
"id": "62a8e21398ad61520edb724f",
"title": "Step 117"
},
{
"id": "62a8e35675c18c56354c08cf",
"id": "62a8e24c673b075317cc0b09",
"title": "Step 118"
},
{
"id": "62a8e41e2f190c58404dd46e",
"id": "62a8e271f8e3d1541f9624ad",
"title": "Step 119"
},
{
"id": "62a8e45cc600c3591cee671a",
"id": "62a8e35675c18c56354c08cf",
"title": "Step 120"
},
{
"id": "62a8e49f4df7af5ae2d7a616",
"id": "62a8e41e2f190c58404dd46e",
"title": "Step 121"
},
{
"id": "62a8e4dc6a60f85bf256a0cb",
"id": "62a8e45cc600c3591cee671a",
"title": "Step 122"
},
{
"id": "62a8ed36d7a7915dfa444ba2",
"id": "62a8e49f4df7af5ae2d7a616",
"title": "Step 123"
},
{
"id": "62a8edd05e27cc668051686f",
"id": "62a8e4dc6a60f85bf256a0cb",
"title": "Step 124"
},
{
"id": "62a8ee154c8946678775c4a4",
"id": "62a8ed36d7a7915dfa444ba2",
"title": "Step 125"
},
{
"id": "62a8ee71f018e968a056d369",
"id": "62a8edd05e27cc668051686f",
"title": "Step 126"
},
{
"id": "62a8eec45f77bc69e8775294",
"id": "62a8ee154c8946678775c4a4",
"title": "Step 127"
},
{
"id": "62a8eefe2e68b66ac563816b",
"id": "62a8ee71f018e968a056d369",
"title": "Step 128"
},
{
"id": "62a8ef6a52292f6bdca4f6f8",
"id": "62a8eec45f77bc69e8775294",
"title": "Step 129"
},
{
"id": "62a8ef8f0c76a46cd221a68c",
"id": "62a8eefe2e68b66ac563816b",
"title": "Step 130"
},
{
"id": "62a8efb0e3ce826db8daf80f",
"id": "62a8ef6a52292f6bdca4f6f8",
"title": "Step 131"
},
{
"id": "62a8eff21c0b0f6ebe5b8e38",
"id": "62a8ef8f0c76a46cd221a68c",
"title": "Step 132"
},
{
"id": "62a8f06fb318666fef69f91e",
"id": "62a8efb0e3ce826db8daf80f",
"title": "Step 133"
},
{
"id": "62a8f14fe6d1fc72454648c7",
"id": "62a8eff21c0b0f6ebe5b8e38",
"title": "Step 134"
},
{
"id": "62a8f1d5f5ddbf74c07f733b",
"id": "62a8f06fb318666fef69f91e",
"title": "Step 135"
},
{
"id": "62a8f20463b324759953edad",
"id": "62a8f14fe6d1fc72454648c7",
"title": "Step 136"
},
{
"id": "62ba17beef16c563069a65d8",
"id": "62a8f1d5f5ddbf74c07f733b",
"title": "Step 137"
},
{
"id": "62a8f256b813a476cae51f49",
"id": "62a8f20463b324759953edad",
"title": "Step 138"
},
{
"id": "65b2f6acce65b7a69751a090",
"id": "62ba17beef16c563069a65d8",
"title": "Step 139"
},
{
"id": "62a8f35bde1750791f58773f",
"id": "62a8f256b813a476cae51f49",
"title": "Step 140"
},
{
"id": "62a94114ce0b8918b487390f",
"id": "65b2f6acce65b7a69751a090",
"title": "Step 141"
},
{
"id": "62aa1cea594f152ba626b872",
"id": "62a8f35bde1750791f58773f",
"title": "Step 142"
},
{
"id": "62aa1d6736ba262cfa74344b",
"id": "62a94114ce0b8918b487390f",
"title": "Step 143"
},
{
"id": "62aa1d9f535e102e4663e7a6",
"id": "62aa1cea594f152ba626b872",
"title": "Step 144"
},
{
"id": "62aa1e3c7c3d552fb04f0f18",
"id": "62aa1d6736ba262cfa74344b",
"title": "Step 145"
},
{
"id": "62aa1e8ccd579330e097ce44",
"id": "62aa1d9f535e102e4663e7a6",
"title": "Step 146"
},
{
"id": "62aa1eec891ed731db227a36",
"id": "62aa1e3c7c3d552fb04f0f18",
"title": "Step 147"
},
{
"id": "62aa1fed3d4e873366ff3131",
"id": "62aa1e8ccd579330e097ce44",
"title": "Step 148"
},
{
"id": "62aa204c1e1d33348ff09944",
"id": "62aa1eec891ed731db227a36",
"title": "Step 149"
},
{
"id": "62aa20e9cf1be9358f5aceae",
"id": "62aa1fed3d4e873366ff3131",
"title": "Step 150"
},
{
"id": "62aa2136fc49b836dfedb959",
"id": "62aa204c1e1d33348ff09944",
"title": "Step 151"
},
{
"id": "62aa21971e3b743844849985",
"id": "62aa20e9cf1be9358f5aceae",
"title": "Step 152"
},
{
"id": "62aa21ea8d9d9f396b95dd87",
"id": "62aa2136fc49b836dfedb959",
"title": "Step 153"
},
{
"id": "62aa226207f33d3ad4c6f546",
"id": "62aa21971e3b743844849985",
"title": "Step 154"
},
{
"id": "62aa22aba186563bcbf2c395",
"id": "62aa21ea8d9d9f396b95dd87",
"title": "Step 155"
},
{
"id": "62aa234322d4ad3e8bce42cc",
"id": "62aa226207f33d3ad4c6f546",
"title": "Step 156"
},
{
"id": "62aa2469c77b363fdb4f0e06",
"id": "62aa22aba186563bcbf2c395",
"title": "Step 157"
},
{
"id": "62aa252c3b1073415ba2b898",
"id": "62aa234322d4ad3e8bce42cc",
"title": "Step 158"
},
{
"id": "62aa258da314ef42ba0a1858",
"id": "62aa2469c77b363fdb4f0e06",
"title": "Step 159"
},
{
"id": "62aa25fcb5837d43b4d9873d",
"id": "62aa252c3b1073415ba2b898",
"title": "Step 160"
},
{
"id": "62aa2626c3c10244b94c787b",
"id": "62aa258da314ef42ba0a1858",
"title": "Step 161"
},
{
"id": "62aa264d23cdaa45a20efada",
"id": "62aa25fcb5837d43b4d9873d",
"title": "Step 162"
},
{
"id": "62aa26cca3cd3d46c431e73b",
"id": "62aa2626c3c10244b94c787b",
"title": "Step 163"
},
{
"id": "62aa27227399d647e1c37a3c",
"id": "62aa264d23cdaa45a20efada",
"title": "Step 164"
},
{
"id": "62aa27560def7048d7b4a095",
"id": "62aa26cca3cd3d46c431e73b",
"title": "Step 165"
},
{
"id": "62aa27c40ca6f04ab8be5fac",
"id": "62aa27227399d647e1c37a3c",
"title": "Step 166"
},
{
"id": "62aa28fb651bf14efa2dbb16",
"id": "62aa27560def7048d7b4a095",
"title": "Step 167"
},
{
"id": "62aa2943669c9d5026af6985",
"id": "62aa27c40ca6f04ab8be5fac",
"title": "Step 168"
},
{
"id": "62aa2999ec27ec516655eba6",
"id": "62aa28fb651bf14efa2dbb16",
"title": "Step 169"
},
{
"id": "62aa29d8f8f88152c91350ca",
"id": "62aa2943669c9d5026af6985",
"title": "Step 170"
},
{
"id": "62aa2aec2f09d454253aad6c",
"id": "62aa2999ec27ec516655eba6",
"title": "Step 171"
},
{
"id": "62aa2ba9cd881355a6f0a5a8",
"id": "62aa29d8f8f88152c91350ca",
"title": "Step 172"
},
{
"id": "62aa2aec2f09d454253aad6c",
"title": "Step 173"
},
{
"id": "62aa2ba9cd881355a6f0a5a8",
"title": "Step 174"
}
]
}

View File

@@ -1,16 +1,20 @@
---
id: 62a8d1c72e8bb13c2074d93c
title: Step 97
title: Step 98
challengeType: 0
dashedName: step-97
dashedName: step-98
---
# --description--
You now have an error to fix. The `currentWeapon` variable is the index of the `weapons` array, but array indexing starts at zero. The index of the last element in an array is one less than the length of the array.
When you were testing your function, you should have seen an error message in the console. This error is due to the condition in the `buyWeapon` function.
The `currentWeapon` variable is the index of the `weapons` array, but array indexing starts at zero. The index of the last element in an array is one less than the length of the array.
Change the `if` condition to check `weapons.length - 1`, instead of `weapons.length`.
Test out your `buyWeapon` function again to see the error message disappear.
# --hints--
You should update the condition to subtract `1` from `weapons.length`.
@@ -42,7 +46,7 @@ assert.match(buyWeapon.toString(), /currentWeapon\s*<\s*weapons\.length\s*-\s*1/
<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>
<span class="stat">Gold: <strong><span id="goldText">250</span></strong></span>
</div>
<div id="controls">
<button id="button1">Go to store</button>
@@ -113,7 +117,7 @@ button {
```js
let xp = 0;
let health = 100;
let gold = 50;
let gold = 250;
let currentWeapon = 0;
let fighting;
let monsterHealth;

View File

@@ -1,14 +1,18 @@
---
id: 62a8d2146a3e853d0a6e28ca
title: Step 98
title: Step 99
challengeType: 0
dashedName: step-98
dashedName: step-99
---
# --description--
If the player has purchased all of the weapons in the inventory, the player should not be able to purchase any more and a message should be displayed.
Add an `else` statement for your outer `if` statement. Inside this new `else` statement, set `text.innerText` to `"You already have the most powerful weapon!"`.
Test your `buyWeapon` function again to make sure the message is displayed when the player has the most powerful weapon.
# --hints--
You should have another `else` statement in your `buyWeapon` function.
@@ -49,7 +53,7 @@ assert.equal(text.innerText, "You already have the most powerful weapon!");
<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>
<span class="stat">Gold: <strong><span id="goldText">250</span></strong></span>
</div>
<div id="controls">
<button id="button1">Go to store</button>
@@ -120,7 +124,7 @@ button {
```js
let xp = 0;
let health = 100;
let gold = 50;
let gold = 250;
let currentWeapon = 0;
let fighting;
let monsterHealth;

View File

@@ -1,8 +1,8 @@
---
id: 62a8d24c97461b3ddb9397c8
title: Step 99
title: Step 101
challengeType: 0
dashedName: step-99
dashedName: step-101
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62a8d2e2a073be3edb46116f
title: Step 100
title: Step 102
challengeType: 0
dashedName: step-100
dashedName: step-102
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62a8d31ebbc10e3fe1b28e03
title: Step 101
title: Step 103
challengeType: 0
dashedName: step-101
dashedName: step-103
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62a8d35660db4040ba292193
title: Step 102
title: Step 104
challengeType: 0
dashedName: step-102
dashedName: step-104
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62a8d382cd075f4169223e14
title: Step 103
title: Step 105
challengeType: 0
dashedName: step-103
dashedName: step-105
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62a8d539dc11cb42b5dd7ec8
title: Step 104
title: Step 106
challengeType: 0
dashedName: step-104
dashedName: step-106
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62a8d61ddfe35744369365b7
title: Step 105
title: Step 107
challengeType: 0
dashedName: step-105
dashedName: step-107
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62a8d6c7001ebc45350e3d16
title: Step 106
title: Step 108
challengeType: 0
dashedName: step-106
dashedName: step-108
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62a8d7b8ab568b4649998954
title: Step 107
title: Step 109
challengeType: 0
dashedName: step-107
dashedName: step-109
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62a8d81f539f004776dd9b1e
title: Step 108
title: Step 110
challengeType: 0
dashedName: step-108
dashedName: step-110
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62a8dd468debb449b4454086
title: Step 109
title: Step 111
challengeType: 0
dashedName: step-109
dashedName: step-111
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62a8dd9cdb16324b04cfd958
title: Step 110
title: Step 112
challengeType: 0
dashedName: step-110
dashedName: step-112
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62a8dfcf7fb1044d2f478fd1
title: Step 111
title: Step 113
challengeType: 0
dashedName: step-111
dashedName: step-113
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62a8e0d1d0110b4ec421489f
title: Step 112
title: Step 114
challengeType: 0
dashedName: step-112
dashedName: step-114
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62a8e142f7f0bd4fed898de3
title: Step 113
title: Step 115
challengeType: 0
dashedName: step-113
dashedName: step-115
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62a8e1dc897df55108bcb5e8
title: Step 114
title: Step 116
challengeType: 0
dashedName: step-114
dashedName: step-116
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62a8e21398ad61520edb724f
title: Step 115
title: Step 117
challengeType: 0
dashedName: step-115
dashedName: step-117
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62a8e24c673b075317cc0b09
title: Step 116
title: Step 118
challengeType: 0
dashedName: step-116
dashedName: step-118
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62a8e271f8e3d1541f9624ad
title: Step 117
title: Step 119
challengeType: 0
dashedName: step-117
dashedName: step-119
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62a8e35675c18c56354c08cf
title: Step 118
title: Step 120
challengeType: 0
dashedName: step-118
dashedName: step-120
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62a8e41e2f190c58404dd46e
title: Step 119
title: Step 121
challengeType: 0
dashedName: step-119
dashedName: step-121
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62a8e45cc600c3591cee671a
title: Step 120
title: Step 122
challengeType: 0
dashedName: step-120
dashedName: step-122
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62a8e49f4df7af5ae2d7a616
title: Step 121
title: Step 123
challengeType: 0
dashedName: step-121
dashedName: step-123
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62a8e4dc6a60f85bf256a0cb
title: Step 122
title: Step 124
challengeType: 0
dashedName: step-122
dashedName: step-124
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62a8ed36d7a7915dfa444ba2
title: Step 123
title: Step 125
challengeType: 0
dashedName: step-123
dashedName: step-125
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62a8edd05e27cc668051686f
title: Step 124
title: Step 126
challengeType: 0
dashedName: step-124
dashedName: step-126
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62a8ee154c8946678775c4a4
title: Step 125
title: Step 127
challengeType: 0
dashedName: step-125
dashedName: step-127
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62a8ee71f018e968a056d369
title: Step 126
title: Step 128
challengeType: 0
dashedName: step-126
dashedName: step-128
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62a8eec45f77bc69e8775294
title: Step 127
title: Step 129
challengeType: 0
dashedName: step-127
dashedName: step-129
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62a8eefe2e68b66ac563816b
title: Step 128
title: Step 130
challengeType: 0
dashedName: step-128
dashedName: step-130
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62a8ef6a52292f6bdca4f6f8
title: Step 129
title: Step 131
challengeType: 0
dashedName: step-129
dashedName: step-131
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62a8ef8f0c76a46cd221a68c
title: Step 130
title: Step 132
challengeType: 0
dashedName: step-130
dashedName: step-132
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62a8efb0e3ce826db8daf80f
title: Step 131
title: Step 133
challengeType: 0
dashedName: step-131
dashedName: step-133
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62a8eff21c0b0f6ebe5b8e38
title: Step 132
title: Step 134
challengeType: 0
dashedName: step-132
dashedName: step-134
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62a8f06fb318666fef69f91e
title: Step 133
title: Step 135
challengeType: 0
dashedName: step-133
dashedName: step-135
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62a8f14fe6d1fc72454648c7
title: Step 134
title: Step 136
challengeType: 0
dashedName: step-134
dashedName: step-136
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62a8f1d5f5ddbf74c07f733b
title: Step 135
title: Step 137
challengeType: 0
dashedName: step-135
dashedName: step-137
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62a8f20463b324759953edad
title: Step 136
title: Step 138
challengeType: 0
dashedName: step-136
dashedName: step-138
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62a8f256b813a476cae51f49
title: Step 138
title: Step 140
challengeType: 0
dashedName: step-138
dashedName: step-140
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62a8f35bde1750791f58773f
title: Step 140
title: Step 142
challengeType: 0
dashedName: step-140
dashedName: step-142
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62a94114ce0b8918b487390f
title: Step 141
title: Step 143
challengeType: 0
dashedName: step-141
dashedName: step-143
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62aa1cea594f152ba626b872
title: Step 142
title: Step 144
challengeType: 0
dashedName: step-142
dashedName: step-144
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62aa1d6736ba262cfa74344b
title: Step 143
title: Step 145
challengeType: 0
dashedName: step-143
dashedName: step-145
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62aa1d9f535e102e4663e7a6
title: Step 144
title: Step 146
challengeType: 0
dashedName: step-144
dashedName: step-146
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62aa1e3c7c3d552fb04f0f18
title: Step 145
title: Step 147
challengeType: 0
dashedName: step-145
dashedName: step-147
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62aa1e8ccd579330e097ce44
title: Step 146
title: Step 148
challengeType: 0
dashedName: step-146
dashedName: step-148
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62aa1eec891ed731db227a36
title: Step 147
title: Step 149
challengeType: 0
dashedName: step-147
dashedName: step-149
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62aa1fed3d4e873366ff3131
title: Step 148
title: Step 150
challengeType: 0
dashedName: step-148
dashedName: step-150
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62aa204c1e1d33348ff09944
title: Step 149
title: Step 151
challengeType: 0
dashedName: step-149
dashedName: step-151
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62aa20e9cf1be9358f5aceae
title: Step 150
title: Step 152
challengeType: 0
dashedName: step-150
dashedName: step-152
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62aa2136fc49b836dfedb959
title: Step 151
title: Step 153
challengeType: 0
dashedName: step-151
dashedName: step-153
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62aa21971e3b743844849985
title: Step 152
title: Step 154
challengeType: 0
dashedName: step-152
dashedName: step-154
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62aa21ea8d9d9f396b95dd87
title: Step 153
title: Step 155
challengeType: 0
dashedName: step-153
dashedName: step-155
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62aa226207f33d3ad4c6f546
title: Step 154
title: Step 156
challengeType: 0
dashedName: step-154
dashedName: step-156
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62aa22aba186563bcbf2c395
title: Step 155
title: Step 157
challengeType: 0
dashedName: step-155
dashedName: step-157
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62aa234322d4ad3e8bce42cc
title: Step 156
title: Step 158
challengeType: 0
dashedName: step-156
dashedName: step-158
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62aa2469c77b363fdb4f0e06
title: Step 157
title: Step 159
challengeType: 0
dashedName: step-157
dashedName: step-159
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62aa252c3b1073415ba2b898
title: Step 158
title: Step 160
challengeType: 0
dashedName: step-158
dashedName: step-160
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62aa258da314ef42ba0a1858
title: Step 159
title: Step 161
challengeType: 0
dashedName: step-159
dashedName: step-161
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62aa25fcb5837d43b4d9873d
title: Step 160
title: Step 162
challengeType: 0
dashedName: step-160
dashedName: step-162
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62aa2626c3c10244b94c787b
title: Step 161
title: Step 163
challengeType: 0
dashedName: step-161
dashedName: step-163
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62aa264d23cdaa45a20efada
title: Step 162
title: Step 164
challengeType: 0
dashedName: step-162
dashedName: step-164
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62aa26cca3cd3d46c431e73b
title: Step 163
title: Step 165
challengeType: 0
dashedName: step-163
dashedName: step-165
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62aa27227399d647e1c37a3c
title: Step 164
title: Step 166
challengeType: 0
dashedName: step-164
dashedName: step-166
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62aa27560def7048d7b4a095
title: Step 165
title: Step 167
challengeType: 0
dashedName: step-165
dashedName: step-167
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62aa27c40ca6f04ab8be5fac
title: Step 166
title: Step 168
challengeType: 0
dashedName: step-166
dashedName: step-168
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62aa28fb651bf14efa2dbb16
title: Step 167
title: Step 169
challengeType: 0
dashedName: step-167
dashedName: step-169
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62aa2943669c9d5026af6985
title: Step 168
title: Step 170
challengeType: 0
dashedName: step-168
dashedName: step-170
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62aa2999ec27ec516655eba6
title: Step 169
title: Step 171
challengeType: 0
dashedName: step-169
dashedName: step-171
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62aa29d8f8f88152c91350ca
title: Step 170
title: Step 172
challengeType: 0
dashedName: step-170
dashedName: step-172
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62aa2aec2f09d454253aad6c
title: Step 171
title: Step 173
challengeType: 0
dashedName: step-171
dashedName: step-173
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62aa2ba9cd881355a6f0a5a8
title: Step 172
title: Step 174
challengeType: 0
dashedName: step-172
dashedName: step-174
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 62ba17beef16c563069a65d8
title: Step 137
title: Step 139
challengeType: 0
dashedName: step-137
dashedName: step-139
---
# --description--

View File

@@ -1,8 +1,8 @@
---
id: 65b2f6acce65b7a69751a090
title: Step 139
title: Step 141
challengeType: 0
dashedName: step-139
dashedName: step-141
---
# --description--

View File

@@ -0,0 +1,226 @@
---
id: 662fbead61552e06d30fc048
title: Step 97
challengeType: 0
dashedName: step-97
---
# --description--
Now it is time to test your `buyWeapon` function. Right now, the `gold` amount is set to `50`. But to properly see the results of your `buyWeapon` function, the amount should be set to something higher.
Update the `gold` amount to `250`.
*NOTE*: The HTML has already been updated to reflect this change.
To test your `buyWeapon` function, open up the console. Then click on the `"Go to store"` button followed by the `"Buy weapon (30 gold)"` button four times.
# --hints--
Your `gold` amount should be set to `250`.
```js
assert.strictEqual(gold, 250);
```
# --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">250</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;
--fcc-editable-region--
let gold = 50;
--fcc-editable-region--
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 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."
}
];
// initialize buttons
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 goTown() {
update(locations[0]);
}
function goStore() {
update(locations[1]);
}
function goCave() {
update(locations[2]);
}
function fightDragon() {
console.log("Fighting dragon.");
}
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) {
if (gold >= 30) {
gold -= 30;
currentWeapon++;
goldText.innerText = gold;
let newWeapon = weapons[currentWeapon].name;
text.innerText = "You now have a " + newWeapon + ".";
inventory.push(newWeapon);
text.innerText += " In your inventory you have: " + inventory;
} else {
text.innerText = "You do not have enough gold to buy a weapon.";
}
}
}
function fightSlime() {
}
function fightBeast() {
}
```

View File

@@ -0,0 +1,223 @@
---
id: 662fc372da60030ae25b194e
title: Step 100
challengeType: 0
dashedName: step-100
---
# --description--
Now that you are finished testing that portion of the `buyWeapon` function, you can set your `gold` variable back to `50`.
*Note*: The HTML has already been updated to reflect the original value of `gold`.
# --hints--
Your `gold` variable should be set to `50`.
```js
assert.equal(gold, 50);
```
# --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;
--fcc-editable-region--
let gold = 250;
--fcc-editable-region--
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 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."
}
];
// initialize buttons
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 goTown() {
update(locations[0]);
}
function goStore() {
update(locations[1]);
}
function goCave() {
update(locations[2]);
}
function fightDragon() {
console.log("Fighting dragon.");
}
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!";
}
}
function fightSlime() {
}
function fightBeast() {
}
```