Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialNeil Martin Orbase
4,137 PointsEnding up making this as a "JavaScript" game!
/* !== 7 Dice Roll Game
RULES: At least 2 players required (otherwise, you can always compete with yourself!).
Open console viewer (Command + Option + J on macOS) on your browser (on any current open webpage or blank page).
Paste game link { http://not7-dicerollgame.surge.sh/ } onto address bar of that same browser window with the open console and 'visit' the link.
Once page opens, the "die roll" simulation begins.
An alert window pops up six times simulating six separate die rolls (click 'OK' or hit 'return/Enter' on keyboard to advance to next window/roll die) and the given randomized number from 1-6 (die roll result).
For each completed two-pair dice roll, the console displays the result of each die roll from the completed set on one line, in which the two results are separated by a comma.
If a pair's (set of numbers on each line) sum equals 7 (result1 + result2 = 7), that line/set automatically receives a score point of 0.
For each pair that does not equate to the sum of 7, that line is eligible for points in which are based on the sum of that pair.
Add up all the points earned.
Refresh page to start the game over for the next player to "roll".
The player with the most points wins the '!==7 Dice Roll' game!
~ github.com/norbase via Treehouse Coding Challenge ~
*/
function getRandomNumber() {
const randomNumber = Math.floor( Math.random() * 6 ) + 1;
return randomNumber;
}
function rollDie() {
const dieRoll = getRandomNumber();
alert(dieRoll);
const dieRoll2 = getRandomNumber();
alert(dieRoll2);
console.log(dieRoll + ', ' + dieRoll2);
}
rollDie();
rollDie();
rollDie();
1 Answer
Steven Parker
231,275 PointsIt's a start! Are you planning to expand it? Some ideas for things you could do:
- total up and display the points for each "turn"
- keep track of each player's totals
- compare the totals and declare a winner
And you'll probably think of some more enhancements while you add these.
Neil Martin Orbase
4,137 PointsNeil Martin Orbase
4,137 PointsThank you for the feedback and awesome tips, Steven!