Skip to content

Commit 274b7bc

Browse files
fix(curriculum): dice game steps fix (freeCodeCamp#55666)
Co-authored-by: Huyen Nguyen <[email protected]>
1 parent 381f167 commit 274b7bc

14 files changed

+111
-122
lines changed

curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/review-algorithmic-thinking-by-building-a-dice-game/657a0ea50da0c8d9d6d7950a.md

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ dashedName: step-1
99

1010
In this project, you will learn algorithmic thinking by building a dice game. There are a total of 6 rounds and for each round, the player can roll the dice up to 3 times and collect a score.
1111

12-
The HTML and CSS have been provided for you. Feel free to explore them. When you are ready, you will need to set up your HTML variables. Get all of your `.die` elements and assign them to a `listOfAllDice` variable. Get your score inputs (the `input` elements in your `#score-options`) and score spans, and assign them to `scoreInputs` and `scoreSpans`. Assign the `#current-round` element to `currentRound` and the `#current-round-rolls` element to `currentRoundRolls`, then do the same for your `#total-score` and `#score-history` elements. Assign your `#roll-dice-btn`, `#keep-score-btn`, `#rules-btn`, and `.rules-container` to variables with properly formatted names.
12+
The HTML and CSS have been provided for you. Feel free to explore them. When you are ready, you will need to set up your HTML variables. Get all of your `.die` elements and assign them to a `listOfAllDice` variable. Get your score inputs (the `input` elements in your `#score-options`) and score spans, and assign them to `scoreInputs` and `scoreSpans`. Assign the `#current-round` element to `roundElement` and the `#current-round-rolls` element to `rollsElement`, then do the same for your `#total-score` and `#score-history` elements. Assign your `#roll-dice-btn`, `#keep-score-btn`, `#rules-btn`, and `.rules-container` to variables with properly formatted names.
1313

1414
When the user clicks on the `Show rules` button, they should be able to toggle between showing and hiding the game rules. Create a variable `isModalShowing` to track the state of the game rules.
1515

1616
Each time the user rolls the dice, you will need to keep track of all of the dice values. Create a variable `diceValuesArr` to track this.
1717

18-
Throughout the game, you will need to keep track of the current score, total score, number of rolls and which round the player is on. Declare `rolls`, `score`, `total`, and `round` variables for this purpose.
18+
Throughout the game, you will need to keep track of the current score, total score, number of rolls and which round the player is on. Declare `rolls`, `score`, and `round` variables for this purpose.
1919

2020
Think about what the starting value of each of these variables should be. All of these variables should be able to be reassigned.
2121

@@ -39,22 +39,22 @@ You should assign your `#score-options span` elements to `scoreSpans`.
3939
assert.deepEqual(scoreSpans, document.querySelectorAll("#score-options span"));
4040
```
4141

42-
You should assign your `#current-round` element to `currentRound`.
42+
You should assign your `#current-round` element to `roundElement`.
4343

4444
```js
45-
assert.deepInclude([document.getElementById("current-round"), document.querySelector("#current-round")], currentRound);
45+
assert.deepInclude([document.getElementById("current-round"), document.querySelector("#current-round")], roundElement);
4646
```
4747

48-
You should assign your `#current-round-rolls` element to `currentRoundRolls`.
48+
You should assign your `#current-round-rolls` element to `rollsElement`.
4949

5050
```js
51-
assert.deepInclude([document.getElementById("current-round-rolls"), document.querySelector("#current-round-rolls")], currentRoundRolls);
51+
assert.deepInclude([document.getElementById("current-round-rolls"), document.querySelector("#current-round-rolls")], rollsElement);
5252
```
5353

54-
You should assign your `#total-score` element to `totalScoreText`.
54+
You should assign your `#total-score` element to `totalScoreElement`.
5555

5656
```js
57-
assert.deepInclude([document.getElementById("total-score"), document.querySelector("#total-score")], totalScore);
57+
assert.deepInclude([document.getElementById("total-score"), document.querySelector("#total-score")], totalScoreElement);
5858
```
5959

6060
You should assign your `#score-history` element to `scoreHistory`.
@@ -112,12 +112,6 @@ Your `score` variable should have the value `0`.
112112
assert.strictEqual(score, 0);
113113
```
114114

115-
Your `total` variable should have the value `0`.
116-
117-
```js
118-
assert.strictEqual(total, 0);
119-
```
120-
121115
Your `round` variable should have the value `1`.
122116

123117
```js
@@ -131,7 +125,6 @@ assert.match(code, /let isModalShowing/);
131125
assert.match(code, /let diceValuesArr/);
132126
assert.match(code, /let rolls/);
133127
assert.match(code, /let score/);
134-
assert.match(code, /let total/);
135128
assert.match(code, /let round/);
136129
```
137130

curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/review-algorithmic-thinking-by-building-a-dice-game/657a19e477dc04e36a86dffc.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,9 @@ input[type="radio"]:disabled + label {
299299
const listOfAllDice = document.querySelectorAll(".die");
300300
const scoreInputs = document.querySelectorAll("#score-options input");
301301
const scoreSpans = document.querySelectorAll("#score-options span");
302-
const currentRound = document.getElementById("current-round");
303-
const currentRoundRolls = document.getElementById("current-round-rolls");
304-
const totalScore = document.getElementById("total-score");
302+
const roundElement = document.getElementById("current-round");
303+
const rollsElement = document.getElementById("current-round-rolls");
304+
const totalScoreElement = document.getElementById("total-score");
305305
const scoreHistory = document.getElementById("score-history");
306306
const rollDiceBtn = document.getElementById("roll-dice-btn");
307307
const keepScoreBtn = document.getElementById("keep-score-btn");
@@ -311,7 +311,6 @@ const rulesBtn = document.getElementById("rules-btn");
311311
let diceValuesArr = [];
312312
let isModalShowing = false;
313313
let score = 0;
314-
let total = 0;
315314
let round = 1;
316315
let rolls = 0;
317316

curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/review-algorithmic-thinking-by-building-a-dice-game/657c91ad5028770fc68d6116.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,9 @@ input[type="radio"]:disabled + label {
290290
const listOfAllDice = document.querySelectorAll(".die");
291291
const scoreInputs = document.querySelectorAll("#score-options input");
292292
const scoreSpans = document.querySelectorAll("#score-options span");
293-
const currentRound = document.getElementById("current-round");
294-
const currentRoundRolls = document.getElementById("current-round-rolls");
295-
const totalScore = document.getElementById("total-score");
293+
const roundElement = document.getElementById("current-round");
294+
const rollsElement = document.getElementById("current-round-rolls");
295+
const totalScoreElement = document.getElementById("total-score");
296296
const scoreHistory = document.getElementById("score-history");
297297
const rollDiceBtn = document.getElementById("roll-dice-btn");
298298
const keepScoreBtn = document.getElementById("keep-score-btn");
@@ -302,7 +302,6 @@ const rulesBtn = document.getElementById("rules-btn");
302302
let diceValuesArr = [];
303303
let isModalShowing = false;
304304
let score = 0;
305-
let total = 0;
306305
let round = 1;
307306
let rolls = 0;
308307
--fcc-editable-region--

curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/review-algorithmic-thinking-by-building-a-dice-game/657ca813b0908a230e3eb488.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,9 @@ input[type="radio"]:disabled + label {
277277
const listOfAllDice = document.querySelectorAll(".die");
278278
const scoreInputs = document.querySelectorAll("#score-options input");
279279
const scoreSpans = document.querySelectorAll("#score-options span");
280-
const currentRound = document.getElementById("current-round");
281-
const currentRoundRolls = document.getElementById("current-round-rolls");
282-
const totalScore = document.getElementById("total-score");
280+
const roundElement = document.getElementById("current-round");
281+
const rollsElement = document.getElementById("current-round-rolls");
282+
const totalScoreElement = document.getElementById("total-score");
283283
const scoreHistory = document.getElementById("score-history");
284284
const rollDiceBtn = document.getElementById("roll-dice-btn");
285285
const keepScoreBtn = document.getElementById("keep-score-btn");
@@ -289,7 +289,6 @@ const rulesBtn = document.getElementById("rules-btn");
289289
let diceValuesArr = [];
290290
let isModalShowing = false;
291291
let score = 0;
292-
let total = 0;
293292
let round = 1;
294293
let rolls = 0;
295294

curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/review-algorithmic-thinking-by-building-a-dice-game/657caa69db80ef25862b1b17.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,28 @@ You should have a function called `updateStats`.
1717
assert.isFunction(updateStats);
1818
```
1919

20-
Your `updateStats` function should update the `currentRoundRolls` element with the correct value.
20+
Your `updateStats` function should update the `rollsElement` element with the correct value.
2121

2222
```js
2323
rolls = 2;
2424
updateStats();
25-
assert.strictEqual(currentRoundRolls.innerText, "2");
25+
assert.strictEqual(rollsElement.innerText, "2");
2626
```
2727

28-
Your `updateStats` function should update the `currentRound` element with the correct value.
28+
Your `updateStats` function should update the `roundElement` element with the correct value.
2929

3030
```js
3131
round = 5;
3232
updateStats();
33-
assert.strictEqual(currentRound.innerText, "5");
33+
assert.strictEqual(roundElement.innerText, "5");
3434
```
3535

3636
Rolling the dice should update the `rolls` correctly.
3737

3838
```js
3939
rolls = 0;
4040
rollDiceBtn.click();
41-
assert.strictEqual(currentRoundRolls.innerText, "1");
41+
assert.strictEqual(rollsElement.innerText, "1");
4242
```
4343

4444
# --seed--
@@ -283,9 +283,9 @@ input[type="radio"]:disabled + label {
283283
const listOfAllDice = document.querySelectorAll(".die");
284284
const scoreInputs = document.querySelectorAll("#score-options input");
285285
const scoreSpans = document.querySelectorAll("#score-options span");
286-
const currentRound = document.getElementById("current-round");
287-
const currentRoundRolls = document.getElementById("current-round-rolls");
288-
const totalScore = document.getElementById("total-score");
286+
const roundElement = document.getElementById("current-round");
287+
const rollsElement = document.getElementById("current-round-rolls");
288+
const totalScoreElement = document.getElementById("total-score");
289289
const scoreHistory = document.getElementById("score-history");
290290
const rollDiceBtn = document.getElementById("roll-dice-btn");
291291
const keepScoreBtn = document.getElementById("keep-score-btn");
@@ -295,7 +295,6 @@ const rulesBtn = document.getElementById("rules-btn");
295295
let diceValuesArr = [];
296296
let isModalShowing = false;
297297
let score = 0;
298-
let total = 0;
299298
let round = 1;
300299
let rolls = 0;
301300

curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/review-algorithmic-thinking-by-building-a-dice-game/657caf204c0d672a35411c31.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,9 @@ input[type="radio"]:disabled + label {
280280
const listOfAllDice = document.querySelectorAll(".die");
281281
const scoreInputs = document.querySelectorAll("#score-options input");
282282
const scoreSpans = document.querySelectorAll("#score-options span");
283-
const currentRound = document.getElementById("current-round");
284-
const currentRoundRolls = document.getElementById("current-round-rolls");
285-
const totalScore = document.getElementById("total-score");
283+
const roundElement = document.getElementById("current-round");
284+
const rollsElement = document.getElementById("current-round-rolls");
285+
const totalScoreElement = document.getElementById("total-score");
286286
const scoreHistory = document.getElementById("score-history");
287287
const rollDiceBtn = document.getElementById("roll-dice-btn");
288288
const keepScoreBtn = document.getElementById("keep-score-btn");
@@ -292,7 +292,6 @@ const rulesBtn = document.getElementById("rules-btn");
292292
let diceValuesArr = [];
293293
let isModalShowing = false;
294294
let score = 0;
295-
let total = 0;
296295
let round = 1;
297296
let rolls = 0;
298297

@@ -310,8 +309,8 @@ const rollDice = () => {
310309
};
311310

312311
const updateStats = () => {
313-
currentRoundRolls.textContent = rolls;
314-
currentRound.textContent = round;
312+
rollsElement.textContent = rolls;
313+
roundElement.textContent = round;
315314
};
316315

317316
--fcc-editable-region--

curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/review-algorithmic-thinking-by-building-a-dice-game/657cf677438e705eab9fd1f9.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,9 @@ input[type="radio"]:disabled + label {
320320
const listOfAllDice = document.querySelectorAll(".die");
321321
const scoreInputs = document.querySelectorAll("#score-options input");
322322
const scoreSpans = document.querySelectorAll("#score-options span");
323-
const currentRound = document.getElementById("current-round");
324-
const currentRoundRolls = document.getElementById("current-round-rolls");
325-
const totalScore = document.getElementById("total-score");
323+
const roundElement = document.getElementById("current-round");
324+
const rollsElement = document.getElementById("current-round-rolls");
325+
const totalScoreElement = document.getElementById("total-score");
326326
const scoreHistory = document.getElementById("score-history");
327327
const rollDiceBtn = document.getElementById("roll-dice-btn");
328328
const keepScoreBtn = document.getElementById("keep-score-btn");
@@ -332,7 +332,6 @@ const rulesBtn = document.getElementById("rules-btn");
332332
let diceValuesArr = [];
333333
let isModalShowing = false;
334334
let score = 0;
335-
let total = 0;
336335
let round = 1;
337336
let rolls = 0;
338337

@@ -350,8 +349,8 @@ const rollDice = () => {
350349
};
351350

352351
const updateStats = () => {
353-
currentRoundRolls.textContent = rolls;
354-
currentRound.textContent = round;
352+
rollsElement.textContent = rolls;
353+
roundElement.textContent = round;
355354
};
356355

357356
const updateRadioOption = (index, score) => {

curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/review-algorithmic-thinking-by-building-a-dice-game/657d1d52d574588677347c7f.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,9 @@ input[type="radio"]:disabled + label {
291291
const listOfAllDice = document.querySelectorAll(".die");
292292
const scoreInputs = document.querySelectorAll("#score-options input");
293293
const scoreSpans = document.querySelectorAll("#score-options span");
294-
const currentRound = document.getElementById("current-round");
295-
const currentRoundRolls = document.getElementById("current-round-rolls");
296-
const totalScore = document.getElementById("total-score");
294+
const roundElement = document.getElementById("current-round");
295+
const rollsElement = document.getElementById("current-round-rolls");
296+
const totalScoreElement = document.getElementById("total-score");
297297
const scoreHistory = document.getElementById("score-history");
298298
const rollDiceBtn = document.getElementById("roll-dice-btn");
299299
const keepScoreBtn = document.getElementById("keep-score-btn");
@@ -303,7 +303,6 @@ const rulesBtn = document.getElementById("rules-btn");
303303
let diceValuesArr = [];
304304
let isModalShowing = false;
305305
let score = 0;
306-
let total = 0;
307306
let round = 1;
308307
let rolls = 0;
309308

@@ -321,8 +320,8 @@ const rollDice = () => {
321320
};
322321

323322
const updateStats = () => {
324-
currentRoundRolls.textContent = rolls;
325-
currentRound.textContent = round;
323+
rollsElement.textContent = rolls;
324+
roundElement.textContent = round;
326325
};
327326

328327
const updateRadioOption = (index, score) => {

curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/review-algorithmic-thinking-by-building-a-dice-game/657d3ab710745d17697c633a.md

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ dashedName: step-9
77

88
# --description--
99

10-
When you roll the dice and make a selection, you are not able to keep the score you selected and move onto the next round. Create an `updateScore` function to add this functionality. Your function will need a parameter for the score option the user selected and the type of score they achieved.
10+
When you roll the dice and make a selection, you are not able to keep the score you selected and move onto the next round.
1111

12-
The function will need to add the value the user selected to the total score, update the total score text on the page, and add a new list item to the score history with the format `${achieved} : ${selectedValue}`.
12+
Create an `updateScore` function to add this functionality. Your function will need two parameters for the user selected score option. The first parameter will be passed the `value` of the radio button, remember this is a string, and the second parameter will be passed the `id` value of the radio button, which is the type of score they achieved.
13+
14+
The function will need to add the user selected value to the score, update the total score text on the page, and add a new `li` element to the score history `ul` element, using the format `${achieved} : ${selectedValue}` for the `li` element content.
1315

1416
# --hints--
1517

@@ -19,6 +21,14 @@ You should have a `updateScore` function.
1921
assert.isFunction(updateScore);
2022
```
2123

24+
Your `updateScore` function should convert string value to integer and add the value to the total score.
25+
26+
```js
27+
score = 0;
28+
updateScore("10", "hi");
29+
assert.strictEqual(score, 10);
30+
```
31+
2232
Your `updateScore` function should add the value of the first parameter to the total score.
2333

2434
```js
@@ -27,12 +37,12 @@ updateScore(10, "hi");
2737
assert.strictEqual(score, 10);
2838
```
2939

30-
Your `updateScore` function should update the text of the `totalScore` element.
40+
Your `updateScore` function should update the text of the `totalScoreElement` element.
3141

3242
```js
3343
score = 0;
3444
updateScore(10, "hi");
35-
assert.strictEqual(totalScore.innerText, "10");
45+
assert.strictEqual(totalScoreElement.innerText, "10");
3646
```
3747

3848
Your `updateScore` function should add a new list item to the `scoreHistory` element.
@@ -293,9 +303,9 @@ input[type="radio"]:disabled + label {
293303
const listOfAllDice = document.querySelectorAll(".die");
294304
const scoreInputs = document.querySelectorAll("#score-options input");
295305
const scoreSpans = document.querySelectorAll("#score-options span");
296-
const currentRound = document.getElementById("current-round");
297-
const currentRoundRolls = document.getElementById("current-round-rolls");
298-
const totalScore = document.getElementById("total-score");
306+
const roundElement = document.getElementById("current-round");
307+
const rollsElement = document.getElementById("current-round-rolls");
308+
const totalScoreElement = document.getElementById("total-score");
299309
const scoreHistory = document.getElementById("score-history");
300310
const rollDiceBtn = document.getElementById("roll-dice-btn");
301311
const keepScoreBtn = document.getElementById("keep-score-btn");
@@ -305,7 +315,6 @@ const rulesBtn = document.getElementById("rules-btn");
305315
let diceValuesArr = [];
306316
let isModalShowing = false;
307317
let score = 0;
308-
let total = 0;
309318
let round = 1;
310319
let rolls = 0;
311320

@@ -323,8 +332,8 @@ const rollDice = () => {
323332
};
324333

325334
const updateStats = () => {
326-
currentRoundRolls.textContent = rolls;
327-
currentRound.textContent = round;
335+
rollsElement.textContent = rolls;
336+
roundElement.textContent = round;
328337
};
329338

330339
const updateRadioOption = (index, score) => {

0 commit comments

Comments
 (0)