mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-03-02 11:07:15 -05:00
fix(curriculum): rename currentWeapon variable to currentWeaponIndex (#54787)
This commit is contained in:
@@ -84,7 +84,7 @@ assert.equal(document.querySelector('#game')?.children?.length, 4);
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -74,7 +74,7 @@ assert(document.querySelectorAll('#stats > .stat')?.[2]?.innerText === 'Gold: 50
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -177,7 +177,7 @@ assert.equal(stat.innerText.trimEnd(), 'Gold: 50');
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -103,7 +103,7 @@ assert.equal(button3.innerText, 'Fight dragon');
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -126,7 +126,7 @@ assert.equal(spanId, 'monsterHealth');
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -66,7 +66,7 @@ assert.equal(text.innerText, "Welcome to Dragon Repeller. You must defeat the dr
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -72,7 +72,7 @@ assert.equal(background, 'rgb(10, 10, 35)');
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -90,7 +90,7 @@ body {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -143,7 +143,7 @@ body {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -104,7 +104,7 @@ body {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -132,7 +132,7 @@ body {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -106,7 +106,7 @@ body {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -7,32 +7,32 @@ dashedName: step-8
|
||||
|
||||
# --description--
|
||||
|
||||
Create another variable called `currentWeapon` and set it to `0`.
|
||||
Create another variable called `currentWeaponIndex` and set it to `0`.
|
||||
|
||||
# --hints--
|
||||
|
||||
You should use `let` to declare a variable called `currentWeapon`.
|
||||
You should use `let` to declare a variable called `currentWeaponIndex`.
|
||||
|
||||
```js
|
||||
assert.match(code, /let\s+currentWeapon/i);
|
||||
assert.match(code, /let\s+currentWeaponIndex/i);
|
||||
```
|
||||
|
||||
You should use camelCase to name your variable.
|
||||
|
||||
```js
|
||||
assert.match(code, /currentWeapon/);
|
||||
assert.match(code, /currentWeaponIndex/);
|
||||
```
|
||||
|
||||
Your `currentWeapon` variable should be set to `0`.
|
||||
Your `currentWeaponIndex` variable should be set to `0`.
|
||||
|
||||
```js
|
||||
assert.equal(currentWeapon, 0);
|
||||
assert.equal(currentWeaponIndex, 0);
|
||||
```
|
||||
|
||||
You should initialize your variable to `0`.
|
||||
|
||||
```js
|
||||
assert.match(code, /let\s+currentWeapon\s*=\s*0/);
|
||||
assert.match(code, /let\s+currentWeaponIndex\s*=\s*0/);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
@@ -54,6 +54,6 @@ assert.match(code, /let\s+fighting\s*;?/);
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
--fcc-editable-region--
|
||||
```
|
||||
|
||||
@@ -93,7 +93,7 @@ assert.include(inventory, "stick");
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
--fcc-editable-region--
|
||||
```
|
||||
|
||||
@@ -75,7 +75,7 @@ assert.match(code, /querySelector\(\s*('|")#button1\1\s*\)/);
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -61,7 +61,7 @@ assert.deepEqual(button1, document.querySelector("#button1"));
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -176,7 +176,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -122,7 +122,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -128,7 +128,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -144,7 +144,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -132,7 +132,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -112,7 +112,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -124,7 +124,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -124,7 +124,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -143,7 +143,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -148,7 +148,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -174,7 +174,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -124,7 +124,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -136,7 +136,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -116,7 +116,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -144,7 +144,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -112,7 +112,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -130,7 +130,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -121,7 +121,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -128,7 +128,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -139,7 +139,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -132,7 +132,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -136,7 +136,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -118,7 +118,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -171,7 +171,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -154,7 +154,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -118,7 +118,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -114,7 +114,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -128,7 +128,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -114,7 +114,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -112,7 +112,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -124,7 +124,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -136,7 +136,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -118,7 +118,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -114,7 +114,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -124,7 +124,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -160,7 +160,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -126,7 +126,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -116,7 +116,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -114,7 +114,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -124,7 +124,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -132,7 +132,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -129,7 +129,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -123,7 +123,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -115,7 +115,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -118,7 +118,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -143,7 +143,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -112,7 +112,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -122,7 +122,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -7,34 +7,34 @@ dashedName: step-84
|
||||
|
||||
# --description--
|
||||
|
||||
The value of the `currentWeapon` variable corresponds to an index in the `weapons` array. The player starts with a `"stick"`, since `currentWeapon` starts at `0` and `weapons[0]` is the `"stick"` weapon.
|
||||
The value of the `currentWeaponIndex` variable corresponds to an index in the `weapons` array. The player starts with a `"stick"`, since `currentWeaponIndex` starts at `0` and `weapons[0]` is the `"stick"` weapon.
|
||||
|
||||
In the `buyWeapon` function, use compound assignment to add `1` to `currentWeapon` - the user is buying the next weapon in the `weapons` array.
|
||||
In the `buyWeapon` function, use compound assignment to add `1` to `currentWeaponIndex` - the user is buying the next weapon in the `weapons` array.
|
||||
|
||||
# --hints--
|
||||
|
||||
You should use compound assignment to add one to `currentWeapon`.
|
||||
You should use compound assignment to add one to `currentWeaponIndex`.
|
||||
|
||||
```js
|
||||
assert.match(buyWeapon.toString(), /currentWeapon\s*\+=\s*1/);
|
||||
assert.match(buyWeapon.toString(), /currentWeaponIndex\s*\+=\s*1/);
|
||||
```
|
||||
|
||||
Your `buyWeapon` function should increase `currentWeapon` by `1`.
|
||||
Your `buyWeapon` function should increase `currentWeaponIndex` by `1`.
|
||||
|
||||
```js
|
||||
gold = 30;
|
||||
currentWeapon = 0;
|
||||
currentWeaponIndex = 0;
|
||||
buyWeapon();
|
||||
assert.equal(currentWeapon, 1);
|
||||
assert.equal(currentWeaponIndex, 1);
|
||||
```
|
||||
|
||||
Your code should be in your `if` statement.
|
||||
|
||||
```js
|
||||
gold = 20;
|
||||
currentWeapon = 0;
|
||||
currentWeaponIndex = 0;
|
||||
buyWeapon();
|
||||
assert.equal(currentWeapon, 0);
|
||||
assert.equal(currentWeaponIndex, 0);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@@ -126,7 +126,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
|
||||
@@ -16,20 +16,20 @@ num++;
|
||||
console.log(num);
|
||||
```
|
||||
|
||||
Change your `currentWeapon` assignment to use the increment operator.
|
||||
Change your `currentWeaponIndex` assignment to use the increment operator.
|
||||
|
||||
# --hints--
|
||||
|
||||
You should use the increment operator to increase `currentWeapon` by `1`.
|
||||
You should use the increment operator to increase `currentWeaponIndex` by `1`.
|
||||
|
||||
```js
|
||||
assert.match(buyWeapon.toString(), /currentWeapon\s*\+\s*\+/);
|
||||
assert.match(buyWeapon.toString(), /currentWeaponIndex\s*\+\s*\+/);
|
||||
```
|
||||
|
||||
You should not use compound assignment to increase `currentWeapon` by `1`.
|
||||
You should not use compound assignment to increase `currentWeaponIndex` by `1`.
|
||||
|
||||
```js
|
||||
assert.notMatch(buyWeapon.toString(), /currentWeapon\s*\+=\s*1/);
|
||||
assert.notMatch(buyWeapon.toString(), /currentWeaponIndex\s*\+=\s*1/);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@@ -121,7 +121,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
@@ -209,7 +209,7 @@ function buyHealth() {
|
||||
function buyWeapon() {
|
||||
if (gold >= 30) {
|
||||
gold -= 30;
|
||||
currentWeapon += 1;
|
||||
currentWeaponIndex += 1;
|
||||
}
|
||||
}
|
||||
--fcc-editable-region--
|
||||
|
||||
@@ -112,7 +112,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
@@ -200,7 +200,7 @@ function buyHealth() {
|
||||
function buyWeapon() {
|
||||
if (gold >= 30) {
|
||||
gold -= 30;
|
||||
currentWeapon++;
|
||||
currentWeaponIndex++;
|
||||
}
|
||||
}
|
||||
--fcc-editable-region--
|
||||
|
||||
@@ -125,7 +125,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
@@ -213,7 +213,7 @@ function buyHealth() {
|
||||
function buyWeapon() {
|
||||
if (gold >= 30) {
|
||||
gold -= 30;
|
||||
currentWeapon++;
|
||||
currentWeaponIndex++;
|
||||
goldText.innerText = gold;
|
||||
|
||||
text.innerText = "You now have a new weapon.";
|
||||
|
||||
@@ -7,7 +7,7 @@ dashedName: step-88
|
||||
|
||||
# --description--
|
||||
|
||||
Use bracket notation to access an object within the `weapons` array and assign it to your `newWeapon` variable. Place the variable `currentWeapon` within the brackets.
|
||||
Use bracket notation to access an object within the `weapons` array and assign it to your `newWeapon` variable. Place the variable `currentWeaponIndex` within the brackets.
|
||||
|
||||
When you use a variable in bracket notation, you are accessing the property or index by the *value* of that variable.
|
||||
|
||||
@@ -19,10 +19,10 @@ let value = array[index];
|
||||
|
||||
# --hints--
|
||||
|
||||
You should update `newWeapon` to have the value of `weapons[currentWeapon]`.
|
||||
You should update `newWeapon` to have the value of `weapons[currentWeaponIndex]`.
|
||||
|
||||
```js
|
||||
assert.match(buyWeapon.toString(), /newWeapon\s*=\s*weapons\s*\[\s*currentWeapon\s*\]/);
|
||||
assert.match(buyWeapon.toString(), /newWeapon\s*=\s*weapons\s*\[\s*currentWeaponIndex\s*\]/);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@@ -114,7 +114,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
@@ -202,7 +202,7 @@ function buyHealth() {
|
||||
function buyWeapon() {
|
||||
if (gold >= 30) {
|
||||
gold -= 30;
|
||||
currentWeapon++;
|
||||
currentWeaponIndex++;
|
||||
goldText.innerText = gold;
|
||||
let newWeapon = weapons;
|
||||
text.innerText = "You now have a new weapon.";
|
||||
|
||||
@@ -7,14 +7,14 @@ dashedName: step-89
|
||||
|
||||
# --description--
|
||||
|
||||
`weapons[currentWeapon]` is an object. Use dot notation to get the `name` property of that object.
|
||||
`weapons[currentWeaponIndex]` is an object. Use dot notation to get the `name` property of that object.
|
||||
|
||||
# --hints--
|
||||
|
||||
You should update `newWeapon` to have the value of `weapons[currentWeapon].name`.
|
||||
You should update `newWeapon` to have the value of `weapons[currentWeaponIndex].name`.
|
||||
|
||||
```js
|
||||
assert.match(buyWeapon.toString(), /newWeapon\s*=\s*weapons\s*\[\s*currentWeapon\s*\]\s*\.name\s*;?/);
|
||||
assert.match(buyWeapon.toString(), /newWeapon\s*=\s*weapons\s*\[\s*currentWeaponIndex\s*\]\s*\.name\s*;?/);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@@ -106,7 +106,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
@@ -194,9 +194,9 @@ function buyHealth() {
|
||||
function buyWeapon() {
|
||||
if (gold >= 30) {
|
||||
gold -= 30;
|
||||
currentWeapon++;
|
||||
currentWeaponIndex++;
|
||||
goldText.innerText = gold;
|
||||
let newWeapon = weapons[currentWeapon];
|
||||
let newWeapon = weapons[currentWeaponIndex];
|
||||
text.innerText = "You now have a new weapon.";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
@@ -216,9 +216,9 @@ function buyHealth() {
|
||||
function buyWeapon() {
|
||||
if (gold >= 30) {
|
||||
gold -= 30;
|
||||
currentWeapon++;
|
||||
currentWeaponIndex++;
|
||||
goldText.innerText = gold;
|
||||
let newWeapon = weapons[currentWeapon].name;
|
||||
let newWeapon = weapons[currentWeaponIndex].name;
|
||||
text.innerText = "You now have a new weapon.";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ Your `buyWeapon` function should add the value of `newWeapon` to the `inventory`
|
||||
|
||||
```js
|
||||
inventory = [];
|
||||
currentWeapon = 0;
|
||||
currentWeaponIndex = 0;
|
||||
buyWeapon();
|
||||
assert.deepEqual(inventory, ["dagger"]);
|
||||
```
|
||||
@@ -129,7 +129,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
@@ -217,9 +217,9 @@ function buyHealth() {
|
||||
function buyWeapon() {
|
||||
if (gold >= 30) {
|
||||
gold -= 30;
|
||||
currentWeapon++;
|
||||
currentWeaponIndex++;
|
||||
goldText.innerText = gold;
|
||||
let newWeapon = weapons[currentWeapon].name;
|
||||
let newWeapon = weapons[currentWeaponIndex].name;
|
||||
text.innerText = "You now have a " + newWeapon + ".";
|
||||
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
@@ -209,9 +209,9 @@ function buyHealth() {
|
||||
function buyWeapon() {
|
||||
if (gold >= 30) {
|
||||
gold -= 30;
|
||||
currentWeapon++;
|
||||
currentWeaponIndex++;
|
||||
goldText.innerText = gold;
|
||||
let newWeapon = weapons[currentWeapon].name;
|
||||
let newWeapon = weapons[currentWeaponIndex].name;
|
||||
text.innerText = "You now have a " + newWeapon + ".";
|
||||
inventory.push(newWeapon);
|
||||
|
||||
|
||||
@@ -112,7 +112,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
@@ -200,9 +200,9 @@ function buyHealth() {
|
||||
function buyWeapon() {
|
||||
if (gold >= 30) {
|
||||
gold -= 30;
|
||||
currentWeapon++;
|
||||
currentWeaponIndex++;
|
||||
goldText.innerText = gold;
|
||||
let newWeapon = weapons[currentWeapon].name;
|
||||
let newWeapon = weapons[currentWeaponIndex].name;
|
||||
text.innerText = "You now have a " + newWeapon + ".";
|
||||
inventory.push(newWeapon);
|
||||
text.innerText += " In your inventory you have: ";
|
||||
|
||||
@@ -127,7 +127,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
@@ -215,9 +215,9 @@ function buyHealth() {
|
||||
function buyWeapon() {
|
||||
if (gold >= 30) {
|
||||
gold -= 30;
|
||||
currentWeapon++;
|
||||
currentWeaponIndex++;
|
||||
goldText.innerText = gold;
|
||||
let newWeapon = weapons[currentWeapon].name;
|
||||
let newWeapon = weapons[currentWeaponIndex].name;
|
||||
text.innerText = "You now have a " + newWeapon + ".";
|
||||
inventory.push(newWeapon);
|
||||
text.innerText += " In your inventory you have: " + inventory;
|
||||
|
||||
@@ -7,20 +7,20 @@ dashedName: step-95
|
||||
|
||||
# --description--
|
||||
|
||||
Once a player has the best weapon, they cannot buy another one. Wrap all of the code in your `buyWeapon` function inside another `if` statement. The condition should check if `currentWeapon` is less than `3` - the index of the last weapon.
|
||||
Once a player has the best weapon, they cannot buy another one. Wrap all of the code in your `buyWeapon` function inside another `if` statement. The condition should check if `currentWeaponIndex` is less than `3` - the index of the last weapon.
|
||||
|
||||
# --hints--
|
||||
|
||||
You should have a new `if` statement that checks if `currentWeapon` is less than `3`.
|
||||
You should have a new `if` statement that checks if `currentWeaponIndex` is less than `3`.
|
||||
|
||||
```js
|
||||
assert.match(buyWeapon.toString(), /currentWeapon\s*\<\s*3/)
|
||||
assert.match(buyWeapon.toString(), /currentWeaponIndex\s*\<\s*3/)
|
||||
```
|
||||
|
||||
Your existing `if` statement should be within your new `if` statement.
|
||||
|
||||
```js
|
||||
currentWeapon = 5;
|
||||
currentWeaponIndex = 5;
|
||||
gold = 50;
|
||||
buyWeapon();
|
||||
assert.equal(gold, 50);
|
||||
@@ -29,7 +29,7 @@ assert.equal(gold, 50);
|
||||
Your existing `else` statement should be within your new `if` statement.
|
||||
|
||||
```js
|
||||
currentWeapon = 5;
|
||||
currentWeaponIndex = 5;
|
||||
gold = 10;
|
||||
buyWeapon();
|
||||
assert.notEqual(text.innerText, "You do not have enough gold to buy a weapon.");
|
||||
@@ -124,7 +124,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
@@ -212,9 +212,9 @@ function buyHealth() {
|
||||
function buyWeapon() {
|
||||
if (gold >= 30) {
|
||||
gold -= 30;
|
||||
currentWeapon++;
|
||||
currentWeaponIndex++;
|
||||
goldText.innerText = gold;
|
||||
let newWeapon = weapons[currentWeapon].name;
|
||||
let newWeapon = weapons[currentWeaponIndex].name;
|
||||
text.innerText = "You now have a " + newWeapon + ".";
|
||||
inventory.push(newWeapon);
|
||||
text.innerText += " In your inventory you have: " + inventory;
|
||||
|
||||
@@ -9,7 +9,7 @@ dashedName: step-96
|
||||
|
||||
Arrays have a `length` property that returns the number of items in the array. You may want to add new values to the `weapons` array in the future.
|
||||
|
||||
Change your `if` condition to check if `currentWeapon` is less than the length of the `weapons` array. An example of checking the length of an array `myArray` would look like `myArray.length`.
|
||||
Change your `if` condition to check if `currentWeaponIndex` is less than the length of the `weapons` array. An example of checking the length of an array `myArray` would look like `myArray.length`.
|
||||
|
||||
# --hints--
|
||||
|
||||
@@ -19,10 +19,10 @@ You should use the `length` property on the `weapons` array.
|
||||
assert.match(buyWeapon.toString(), /weapons\.length/);
|
||||
```
|
||||
|
||||
Your `if` statement should check if `currentWeapon` is less than `weapons.length`.
|
||||
Your `if` statement should check if `currentWeaponIndex` is less than `weapons.length`.
|
||||
|
||||
```js
|
||||
assert.match(buyWeapon.toString(), /currentWeapon\s*<\s*weapons\.length/);
|
||||
assert.match(buyWeapon.toString(), /currentWeaponIndex\s*<\s*weapons\.length/);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@@ -114,7 +114,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
@@ -200,12 +200,12 @@ function buyHealth() {
|
||||
|
||||
--fcc-editable-region--
|
||||
function buyWeapon() {
|
||||
if (currentWeapon < 3) {
|
||||
if (currentWeaponIndex < 3) {
|
||||
if (gold >= 30) {
|
||||
gold -= 30;
|
||||
currentWeapon++;
|
||||
currentWeaponIndex++;
|
||||
goldText.innerText = gold;
|
||||
let newWeapon = weapons[currentWeapon].name;
|
||||
let newWeapon = weapons[currentWeaponIndex].name;
|
||||
text.innerText = "You now have a " + newWeapon + ".";
|
||||
inventory.push(newWeapon);
|
||||
text.innerText += " In your inventory you have: " + inventory;
|
||||
|
||||
@@ -9,7 +9,7 @@ dashedName: step-98
|
||||
|
||||
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.
|
||||
The `currentWeaponIndex` 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`.
|
||||
|
||||
@@ -23,10 +23,10 @@ You should update the condition to subtract `1` from `weapons.length`.
|
||||
assert.match(buyWeapon.toString(), /weapons\.length\s*-\s*1/);
|
||||
```
|
||||
|
||||
Your condition should check if `currentWeapon` is less than `weapons.length - 1`.
|
||||
Your condition should check if `currentWeaponIndex` is less than `weapons.length - 1`.
|
||||
|
||||
```js
|
||||
assert.match(buyWeapon.toString(), /currentWeapon\s*<\s*weapons\.length\s*-\s*1/);
|
||||
assert.match(buyWeapon.toString(), /currentWeaponIndex\s*<\s*weapons\.length\s*-\s*1/);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@@ -118,7 +118,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 250;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
@@ -204,12 +204,12 @@ function buyHealth() {
|
||||
|
||||
--fcc-editable-region--
|
||||
function buyWeapon() {
|
||||
if (currentWeapon < weapons.length) {
|
||||
if (currentWeaponIndex < weapons.length) {
|
||||
if (gold >= 30) {
|
||||
gold -= 30;
|
||||
currentWeapon++;
|
||||
currentWeaponIndex++;
|
||||
goldText.innerText = gold;
|
||||
let newWeapon = weapons[currentWeapon].name;
|
||||
let newWeapon = weapons[currentWeaponIndex].name;
|
||||
text.innerText = "You now have a " + newWeapon + ".";
|
||||
inventory.push(newWeapon);
|
||||
text.innerText += " In your inventory you have: " + inventory;
|
||||
|
||||
@@ -31,7 +31,7 @@ assert.match(buyWeapon.toString(), /('|")You already have the most powerful weap
|
||||
You should modify your `text.innerText` to `"You already have the most powerful weapon!"` within your outer `else` statement.
|
||||
|
||||
```js
|
||||
currentWeapon = 5;
|
||||
currentWeaponIndex = 5;
|
||||
buyWeapon();
|
||||
assert.equal(text.innerText, "You already have the most powerful weapon!");
|
||||
```
|
||||
@@ -125,7 +125,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 250;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
@@ -211,12 +211,12 @@ function buyHealth() {
|
||||
|
||||
--fcc-editable-region--
|
||||
function buyWeapon() {
|
||||
if (currentWeapon < weapons.length - 1) {
|
||||
if (currentWeaponIndex < weapons.length - 1) {
|
||||
if (gold >= 30) {
|
||||
gold -= 30;
|
||||
currentWeapon++;
|
||||
currentWeaponIndex++;
|
||||
goldText.innerText = gold;
|
||||
let newWeapon = weapons[currentWeapon].name;
|
||||
let newWeapon = weapons[currentWeaponIndex].name;
|
||||
text.innerText = "You now have a " + newWeapon + ".";
|
||||
inventory.push(newWeapon);
|
||||
text.innerText += " In your inventory you have: " + inventory;
|
||||
|
||||
@@ -126,7 +126,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
@@ -212,12 +212,12 @@ function buyHealth() {
|
||||
|
||||
--fcc-editable-region--
|
||||
function buyWeapon() {
|
||||
if (currentWeapon < weapons.length - 1) {
|
||||
if (currentWeaponIndex < weapons.length - 1) {
|
||||
if (gold >= 30) {
|
||||
gold -= 30;
|
||||
currentWeapon++;
|
||||
currentWeaponIndex++;
|
||||
goldText.innerText = gold;
|
||||
let newWeapon = weapons[currentWeapon].name;
|
||||
let newWeapon = weapons[currentWeaponIndex].name;
|
||||
text.innerText = "You now have a " + newWeapon + ".";
|
||||
inventory.push(newWeapon);
|
||||
text.innerText += " In your inventory you have: " + inventory;
|
||||
|
||||
@@ -112,7 +112,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
@@ -197,12 +197,12 @@ function buyHealth() {
|
||||
}
|
||||
|
||||
function buyWeapon() {
|
||||
if (currentWeapon < weapons.length - 1) {
|
||||
if (currentWeaponIndex < weapons.length - 1) {
|
||||
if (gold >= 30) {
|
||||
gold -= 30;
|
||||
currentWeapon++;
|
||||
currentWeaponIndex++;
|
||||
goldText.innerText = gold;
|
||||
let newWeapon = weapons[currentWeapon].name;
|
||||
let newWeapon = weapons[currentWeaponIndex].name;
|
||||
text.innerText = "You now have a " + newWeapon + ".";
|
||||
inventory.push(newWeapon);
|
||||
text.innerText += " In your inventory you have: " + inventory;
|
||||
|
||||
@@ -112,7 +112,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
@@ -197,12 +197,12 @@ function buyHealth() {
|
||||
}
|
||||
|
||||
function buyWeapon() {
|
||||
if (currentWeapon < weapons.length - 1) {
|
||||
if (currentWeaponIndex < weapons.length - 1) {
|
||||
if (gold >= 30) {
|
||||
gold -= 30;
|
||||
currentWeapon++;
|
||||
currentWeaponIndex++;
|
||||
goldText.innerText = gold;
|
||||
let newWeapon = weapons[currentWeapon].name;
|
||||
let newWeapon = weapons[currentWeaponIndex].name;
|
||||
text.innerText = "You now have a " + newWeapon + ".";
|
||||
inventory.push(newWeapon);
|
||||
text.innerText += " In your inventory you have: " + inventory;
|
||||
|
||||
@@ -121,7 +121,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
@@ -206,12 +206,12 @@ function buyHealth() {
|
||||
}
|
||||
|
||||
function buyWeapon() {
|
||||
if (currentWeapon < weapons.length - 1) {
|
||||
if (currentWeaponIndex < weapons.length - 1) {
|
||||
if (gold >= 30) {
|
||||
gold -= 30;
|
||||
currentWeapon++;
|
||||
currentWeaponIndex++;
|
||||
goldText.innerText = gold;
|
||||
let newWeapon = weapons[currentWeapon].name;
|
||||
let newWeapon = weapons[currentWeaponIndex].name;
|
||||
text.innerText = "You now have a " + newWeapon + ".";
|
||||
inventory.push(newWeapon);
|
||||
text.innerText += " In your inventory you have: " + inventory;
|
||||
|
||||
@@ -9,10 +9,6 @@ dashedName: step-105
|
||||
|
||||
The next step is to create a variable called `currentWeapon`.
|
||||
|
||||
Notice that you already have a `currentWeapon` variable elsewhere in your code. Since this new `currentWeapon` variable will be inside an `if` statement, it will be scoped only to that block of code.
|
||||
|
||||
Scope is the term used to describe where a variable can be accessed. If a variable is declared inside a block of code, it is only accessible to the code inside that block. This is called block scope.
|
||||
|
||||
```js
|
||||
let num = 1;
|
||||
if (num === 1) {
|
||||
@@ -121,7 +117,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
@@ -206,12 +202,12 @@ function buyHealth() {
|
||||
}
|
||||
|
||||
function buyWeapon() {
|
||||
if (currentWeapon < weapons.length - 1) {
|
||||
if (currentWeaponIndex < weapons.length - 1) {
|
||||
if (gold >= 30) {
|
||||
gold -= 30;
|
||||
currentWeapon++;
|
||||
currentWeaponIndex++;
|
||||
goldText.innerText = gold;
|
||||
let newWeapon = weapons[currentWeapon].name;
|
||||
let newWeapon = weapons[currentWeaponIndex].name;
|
||||
text.innerText = "You now have a " + newWeapon + ".";
|
||||
inventory.push(newWeapon);
|
||||
text.innerText += " In your inventory you have: " + inventory;
|
||||
|
||||
@@ -126,7 +126,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
@@ -211,12 +211,12 @@ function buyHealth() {
|
||||
}
|
||||
|
||||
function buyWeapon() {
|
||||
if (currentWeapon < weapons.length - 1) {
|
||||
if (currentWeaponIndex < weapons.length - 1) {
|
||||
if (gold >= 30) {
|
||||
gold -= 30;
|
||||
currentWeapon++;
|
||||
currentWeaponIndex++;
|
||||
goldText.innerText = gold;
|
||||
let newWeapon = weapons[currentWeapon].name;
|
||||
let newWeapon = weapons[currentWeaponIndex].name;
|
||||
text.innerText = "You now have a " + newWeapon + ".";
|
||||
inventory.push(newWeapon);
|
||||
text.innerText += " In your inventory you have: " + inventory;
|
||||
|
||||
@@ -26,13 +26,13 @@ assert.match(sellWeapon.toString(), /text\.innerText\s*=\s*('|")You sold a \1/);
|
||||
You should add the value of `currentWeapon` to the `"You sold a "` string. Use the concatenation operator to do this on the same line.
|
||||
|
||||
```js
|
||||
assert.match(sellWeapon.toString(), /text\.innerText\s*=\s*('|")You sold a\s\1\s*\+\s*\_currentWeapon/);
|
||||
assert.match(sellWeapon.toString(), /text\.innerText\s*=\s*('|")You sold a\s\1\s*\+\s*currentWeapon/);
|
||||
```
|
||||
|
||||
You should add the string `"."` to the value of `currentWeapon`. Use the concatenation operator to do this on the same line.
|
||||
|
||||
```js
|
||||
assert.match(sellWeapon.toString(), /text\.innerText\s*=\s*('|")You sold a \1\s*\+\s*\_currentWeapon\s+\+\s+('|")\.\2/);
|
||||
assert.match(sellWeapon.toString(), /text\.innerText\s*=\s*('|")You sold a \1\s*\+\s*currentWeapon\s+\+\s+('|")\.\2/);
|
||||
```
|
||||
|
||||
Your `text.innerText` should update to the proper string.
|
||||
@@ -133,7 +133,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
@@ -218,12 +218,12 @@ function buyHealth() {
|
||||
}
|
||||
|
||||
function buyWeapon() {
|
||||
if (currentWeapon < weapons.length - 1) {
|
||||
if (currentWeaponIndex < weapons.length - 1) {
|
||||
if (gold >= 30) {
|
||||
gold -= 30;
|
||||
currentWeapon++;
|
||||
currentWeaponIndex++;
|
||||
goldText.innerText = gold;
|
||||
let newWeapon = weapons[currentWeapon].name;
|
||||
let newWeapon = weapons[currentWeaponIndex].name;
|
||||
text.innerText = "You now have a " + newWeapon + ".";
|
||||
inventory.push(newWeapon);
|
||||
text.innerText += " In your inventory you have: " + inventory;
|
||||
|
||||
@@ -126,7 +126,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
@@ -211,12 +211,12 @@ function buyHealth() {
|
||||
}
|
||||
|
||||
function buyWeapon() {
|
||||
if (currentWeapon < weapons.length - 1) {
|
||||
if (currentWeaponIndex < weapons.length - 1) {
|
||||
if (gold >= 30) {
|
||||
gold -= 30;
|
||||
currentWeapon++;
|
||||
currentWeaponIndex++;
|
||||
goldText.innerText = gold;
|
||||
let newWeapon = weapons[currentWeapon].name;
|
||||
let newWeapon = weapons[currentWeaponIndex].name;
|
||||
text.innerText = "You now have a " + newWeapon + ".";
|
||||
inventory.push(newWeapon);
|
||||
text.innerText += " In your inventory you have: " + inventory;
|
||||
|
||||
@@ -120,7 +120,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
@@ -205,12 +205,12 @@ function buyHealth() {
|
||||
}
|
||||
|
||||
function buyWeapon() {
|
||||
if (currentWeapon < weapons.length - 1) {
|
||||
if (currentWeaponIndex < weapons.length - 1) {
|
||||
if (gold >= 30) {
|
||||
gold -= 30;
|
||||
currentWeapon++;
|
||||
currentWeaponIndex++;
|
||||
goldText.innerText = gold;
|
||||
let newWeapon = weapons[currentWeapon].name;
|
||||
let newWeapon = weapons[currentWeaponIndex].name;
|
||||
text.innerText = "You now have a " + newWeapon + ".";
|
||||
inventory.push(newWeapon);
|
||||
text.innerText += " In your inventory you have: " + inventory;
|
||||
|
||||
@@ -190,7 +190,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
@@ -274,12 +274,12 @@ function buyHealth() {
|
||||
}
|
||||
|
||||
function buyWeapon() {
|
||||
if (currentWeapon < weapons.length - 1) {
|
||||
if (currentWeaponIndex < weapons.length - 1) {
|
||||
if (gold >= 30) {
|
||||
gold -= 30;
|
||||
currentWeapon++;
|
||||
currentWeaponIndex++;
|
||||
goldText.innerText = gold;
|
||||
let newWeapon = weapons[currentWeapon].name;
|
||||
let newWeapon = weapons[currentWeaponIndex].name;
|
||||
text.innerText = "You now have a " + newWeapon + ".";
|
||||
inventory.push(newWeapon);
|
||||
text.innerText += " In your inventory you have: " + inventory;
|
||||
|
||||
@@ -112,7 +112,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
@@ -210,12 +210,12 @@ function buyHealth() {
|
||||
}
|
||||
|
||||
function buyWeapon() {
|
||||
if (currentWeapon < weapons.length - 1) {
|
||||
if (currentWeaponIndex < weapons.length - 1) {
|
||||
if (gold >= 30) {
|
||||
gold -= 30;
|
||||
currentWeapon++;
|
||||
currentWeaponIndex++;
|
||||
goldText.innerText = gold;
|
||||
let newWeapon = weapons[currentWeapon].name;
|
||||
let newWeapon = weapons[currentWeaponIndex].name;
|
||||
text.innerText = "You now have a " + newWeapon + ".";
|
||||
inventory.push(newWeapon);
|
||||
text.innerText += " In your inventory you have: " + inventory;
|
||||
|
||||
@@ -120,7 +120,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
@@ -218,12 +218,12 @@ function buyHealth() {
|
||||
}
|
||||
|
||||
function buyWeapon() {
|
||||
if (currentWeapon < weapons.length - 1) {
|
||||
if (currentWeaponIndex < weapons.length - 1) {
|
||||
if (gold >= 30) {
|
||||
gold -= 30;
|
||||
currentWeapon++;
|
||||
currentWeaponIndex++;
|
||||
goldText.innerText = gold;
|
||||
let newWeapon = weapons[currentWeapon].name;
|
||||
let newWeapon = weapons[currentWeaponIndex].name;
|
||||
text.innerText = "You now have a " + newWeapon + ".";
|
||||
inventory.push(newWeapon);
|
||||
text.innerText += " In your inventory you have: " + inventory;
|
||||
|
||||
@@ -118,7 +118,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
@@ -216,12 +216,12 @@ function buyHealth() {
|
||||
}
|
||||
|
||||
function buyWeapon() {
|
||||
if (currentWeapon < weapons.length - 1) {
|
||||
if (currentWeaponIndex < weapons.length - 1) {
|
||||
if (gold >= 30) {
|
||||
gold -= 30;
|
||||
currentWeapon++;
|
||||
currentWeaponIndex++;
|
||||
goldText.innerText = gold;
|
||||
let newWeapon = weapons[currentWeapon].name;
|
||||
let newWeapon = weapons[currentWeaponIndex].name;
|
||||
text.innerText = "You now have a " + newWeapon + ".";
|
||||
inventory.push(newWeapon);
|
||||
text.innerText += " In your inventory you have: " + inventory;
|
||||
|
||||
@@ -124,7 +124,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
@@ -222,12 +222,12 @@ function buyHealth() {
|
||||
}
|
||||
|
||||
function buyWeapon() {
|
||||
if (currentWeapon < weapons.length - 1) {
|
||||
if (currentWeaponIndex < weapons.length - 1) {
|
||||
if (gold >= 30) {
|
||||
gold -= 30;
|
||||
currentWeapon++;
|
||||
currentWeaponIndex++;
|
||||
goldText.innerText = gold;
|
||||
let newWeapon = weapons[currentWeapon].name;
|
||||
let newWeapon = weapons[currentWeaponIndex].name;
|
||||
text.innerText = "You now have a " + newWeapon + ".";
|
||||
inventory.push(newWeapon);
|
||||
text.innerText += " In your inventory you have: " + inventory;
|
||||
|
||||
@@ -136,7 +136,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
@@ -236,12 +236,12 @@ function buyHealth() {
|
||||
}
|
||||
|
||||
function buyWeapon() {
|
||||
if (currentWeapon < weapons.length - 1) {
|
||||
if (currentWeaponIndex < weapons.length - 1) {
|
||||
if (gold >= 30) {
|
||||
gold -= 30;
|
||||
currentWeapon++;
|
||||
currentWeaponIndex++;
|
||||
goldText.innerText = gold;
|
||||
let newWeapon = weapons[currentWeapon].name;
|
||||
let newWeapon = weapons[currentWeaponIndex].name;
|
||||
text.innerText = "You now have a " + newWeapon + ".";
|
||||
inventory.push(newWeapon);
|
||||
text.innerText += " In your inventory you have: " + inventory;
|
||||
|
||||
@@ -112,7 +112,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
@@ -216,12 +216,12 @@ function buyHealth() {
|
||||
}
|
||||
|
||||
function buyWeapon() {
|
||||
if (currentWeapon < weapons.length - 1) {
|
||||
if (currentWeaponIndex < weapons.length - 1) {
|
||||
if (gold >= 30) {
|
||||
gold -= 30;
|
||||
currentWeapon++;
|
||||
currentWeaponIndex++;
|
||||
goldText.innerText = gold;
|
||||
let newWeapon = weapons[currentWeapon].name;
|
||||
let newWeapon = weapons[currentWeaponIndex].name;
|
||||
text.innerText = "You now have a " + newWeapon + ".";
|
||||
inventory.push(newWeapon);
|
||||
text.innerText += " In your inventory you have: " + inventory;
|
||||
|
||||
@@ -112,7 +112,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
@@ -216,12 +216,12 @@ function buyHealth() {
|
||||
}
|
||||
|
||||
function buyWeapon() {
|
||||
if (currentWeapon < weapons.length - 1) {
|
||||
if (currentWeaponIndex < weapons.length - 1) {
|
||||
if (gold >= 30) {
|
||||
gold -= 30;
|
||||
currentWeapon++;
|
||||
currentWeaponIndex++;
|
||||
goldText.innerText = gold;
|
||||
let newWeapon = weapons[currentWeapon].name;
|
||||
let newWeapon = weapons[currentWeaponIndex].name;
|
||||
text.innerText = "You now have a " + newWeapon + ".";
|
||||
inventory.push(newWeapon);
|
||||
text.innerText += " In your inventory you have: " + inventory;
|
||||
|
||||
@@ -129,7 +129,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
@@ -233,12 +233,12 @@ function buyHealth() {
|
||||
}
|
||||
|
||||
function buyWeapon() {
|
||||
if (currentWeapon < weapons.length - 1) {
|
||||
if (currentWeaponIndex < weapons.length - 1) {
|
||||
if (gold >= 30) {
|
||||
gold -= 30;
|
||||
currentWeapon++;
|
||||
currentWeaponIndex++;
|
||||
goldText.innerText = gold;
|
||||
let newWeapon = weapons[currentWeapon].name;
|
||||
let newWeapon = weapons[currentWeaponIndex].name;
|
||||
text.innerText = "You now have a " + newWeapon + ".";
|
||||
inventory.push(newWeapon);
|
||||
text.innerText += " In your inventory you have: " + inventory;
|
||||
|
||||
@@ -126,7 +126,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
@@ -230,12 +230,12 @@ function buyHealth() {
|
||||
}
|
||||
|
||||
function buyWeapon() {
|
||||
if (currentWeapon < weapons.length - 1) {
|
||||
if (currentWeaponIndex < weapons.length - 1) {
|
||||
if (gold >= 30) {
|
||||
gold -= 30;
|
||||
currentWeapon++;
|
||||
currentWeaponIndex++;
|
||||
goldText.innerText = gold;
|
||||
let newWeapon = weapons[currentWeapon].name;
|
||||
let newWeapon = weapons[currentWeaponIndex].name;
|
||||
text.innerText = "You now have a " + newWeapon + ".";
|
||||
inventory.push(newWeapon);
|
||||
text.innerText += " In your inventory you have: " + inventory;
|
||||
|
||||
@@ -124,7 +124,7 @@ button {
|
||||
let xp = 0;
|
||||
let health = 100;
|
||||
let gold = 50;
|
||||
let currentWeapon = 0;
|
||||
let currentWeaponIndex = 0;
|
||||
let fighting;
|
||||
let monsterHealth;
|
||||
let inventory = ["stick"];
|
||||
@@ -228,12 +228,12 @@ function buyHealth() {
|
||||
}
|
||||
|
||||
function buyWeapon() {
|
||||
if (currentWeapon < weapons.length - 1) {
|
||||
if (currentWeaponIndex < weapons.length - 1) {
|
||||
if (gold >= 30) {
|
||||
gold -= 30;
|
||||
currentWeapon++;
|
||||
currentWeaponIndex++;
|
||||
goldText.innerText = gold;
|
||||
let newWeapon = weapons[currentWeapon].name;
|
||||
let newWeapon = weapons[currentWeaponIndex].name;
|
||||
text.innerText = "You now have a " + newWeapon + ".";
|
||||
inventory.push(newWeapon);
|
||||
text.innerText += " In your inventory you have: " + inventory;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user