Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
Latest commit
41 lines (35 loc) · 1008 Bytes
/
Copy pathscript.js
File metadata and controls
41 lines (35 loc) · 1008 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
console.log('Hello, World!');
constrollDice=()=>Math.floor(Math.random()*6)+1;
constplayGame=()=>{
letplayer1Score=0;
letplayer2Score=0;
for(leti=0;i<5;i++){
constplayer1Roll=rollDice();
constplayer2Roll=rollDice();
console.log(
`Round ${
i+1
}: Player 1 rolled ${player1Roll}, Player 2 rolled ${player2Roll}`
);
if(player1Roll>player2Roll){
player1Score++;
console.log('Player 1 wins this round!');
}elseif(player2Roll>player1Roll){
player2Score++;
console.log('Player 2 wins this round!');
}else{
console.log("It's a tie!");
}
}
console.log(
`Final Score: Player 1 - ${player1Score}, Player 2 - ${player2Score}`
);
if(player1Score>player2Score){
console.log('Player 1 wins the game!');
}elseif(player2Score>player1Score){
console.log('Player 2 wins the game!');
}else{
console.log('The game is a tie!');
}
};
playGame();