Roll The Dice Game #dicegames #beginnerjavascript

preview_player
Показать описание
This is just a basic structure and there are many ways you can customize and add more features to the game.
1. First, import the random module to generate random numbers for the dice rolls.
2. Define a function that will simulate a dice roll. This function should generate a random number between 1 and 6, which represents the number on the face of the dice.
3. Define a function that will ask the player if they want to roll the dice. If they say yes, call the dice roll function from step 2 and display the result. If they say no, end the game.
4. Define a function that will keep track of the player's score. Each time the player rolls the dice, add the result to their score.
5. Define a function that will check if the player has won or lost. If their score is greater than or equal to 20, they win. If their score is less than 20, they lose.
6. Put all of these functions together in a while loop that will continue until the player wins or loses. At each iteration of the loop, ask the player if they want to roll the dice, update their score, and check if they have won or lost.
7. Once the game is over, display a message to the player indicating whether they won or lost and their final score.

In this article, we will introduce you to important DOM concepts by building roll the dice game. This article will be divided into five core sections so that you can follow along.
So as to fully understand how to code rolling the dice game, let us be familiar with the rule of the game.

The game has 2 players, playing in rounds
In each turn, a player rolls a dice as many times as he whishes. Each result get added to his ROUND score
BUT, if the player rolls a 1, all his ROUND score gets lost. After that, it's the next player's turn
The player can choose to 'Hold', which means that his ROUND score gets added to his GLOBAL score. After that, it's the next player's turn
The first player to reach 50 points on GLOBAL score wins the game
We will, now, work on building our Dice game and learn DOM concepts along the way.

Step 1 of this app: create a random number
Step 2 of this app: create first click event
Step 3 of this app: complement first click event
Step 4 of this app: create second click event
Step 5 of this app: create third click event

Social Media

Twitter

GitHub

FaceBook

Instagram
Рекомендации по теме
Комментарии
Автор

This video is the best, If you see this video I am sure you will review all the thing which you learn in javascript according founction, loops, class, and so on. SUBSCRIBE THE CHANNEL Nice 👌

lordlevi
Автор

bro how this active class worked as we used classlist to add new class and active is already specified in dice class. and how we can define that you gave active name also in dice class by using space which is dice active.

annujtiwarii
Автор

thanks as this video i learn how to use random function

artsgallerytv
Автор

I followed the same steps as you did but i am not able to se 1to6 numbers inside the cube..
Plz can you say what should I do

_bhutadavanshika