Skip to content

Commit 2e2ccd8

Browse files
committed
Use the .querySelector method to set the dice value on this HTML element
Add comments to walkthrough the process
1 parent 593afe1 commit 2e2ccd8

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

JS_Basic_Challenges/.DS_Store

0 Bytes
Binary file not shown.

JS_Basic_Challenges/4-DOM-pig-game/starter/app.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,15 @@ GAME RULES:
1313

1414
var totalScore, currentScore, activePlayer, dice;
1515

16-
var totalScore = [0,0]; // the total score each player has, added together, after multiple rounds of rolling the dice
16+
var totalScore = [0,0]; // the total score each player has, added together, after multiple rounds of rolling the dice
1717
var currentScore = 0; // the score each player has per round/ session, when it's they're actively rolling the dice
18-
var activePlayer = 0; // the player that is currently rolling the dice
18+
var activePlayer = 0; // the player that is currently rolling the dice (can either be 0 or 1)
1919

2020
dice = Math.floor(Math.random() * 6) + 1; // create a dice that generates a random number from 1 to 6 (included)
21+
22+
// Use the 'querySelector' method to select and change the value of the html element with the id starting with "current-".
23+
// The 'textContent' property sets or returns the text content of the node you specify. In our case, that's the dice value of the player rolling it.
24+
// Use concatenation (+) to create a dynamic class; the player can either be 0 (id="current-0") or 1 (id="current-1").
25+
document.querySelector('#current-' + activePlayer).textContent = dice;
26+
// Longer version: document.querySelector('#current-' + activePlayer).textContent = Math.floor(Math.random() * 6) + 1;
27+

0 commit comments

Comments
 (0)