|
1 | | -const choices = ["rock", "paper", "scissors"]; |
2 | | -const playerDisplay = document.getElementById("playerDisplay"); //player choice display |
3 | | -const compDisplay = document.getElementById("compDisplay");//comp choice display |
4 | | -const resultDisplay = document.getElementById("resultDisplay");//result |
5 | | -const playerScoreDisplay = document.getElementById("playerScoreDisplay");//pllayer score |
6 | | -const compScoreDisplay = document.getElementById("compScoreDisplay");//comp score |
| 1 | +const choices = ["Rock", "Paper", "Scissors"]; |
| 2 | +const playerDisplay = document.getElementById("playerDisplay"); |
| 3 | +const compDisplay = document.getElementById("compDisplay"); |
| 4 | +const resultDisplay = document.getElementById("resultDisplay"); |
| 5 | +const playerScoreDisplay = document.getElementById("playerScoreDisplay"); |
| 6 | +const compScoreDisplay = document.getElementById("compScoreDisplay"); |
7 | 7 | let playerScore = 0; |
8 | 8 | let compScore = 0; |
9 | 9 | function playGame(playerChoice){ |
10 | | - const compChoice = choices[Math.floor(Math.random()*3)]; // 0-2 tak ke result ke liye |
| 10 | + const compChoice = choices[Math.floor(Math.random()*3)]; |
11 | 11 | let result = ""; |
12 | 12 | if(playerChoice === compChoice){ |
13 | | - result = "It's a Tie!!"; |
| 13 | + result = "It's a Tie!"; |
14 | 14 | } |
15 | 15 | else { |
16 | 16 | switch (playerChoice) { |
17 | | - case "rock": |
18 | | - if (compChoice === "scissors") { |
19 | | - result = "You Win!!"; |
| 17 | + case "Rock": |
| 18 | + if (compChoice === "Scissors") { |
| 19 | + result = "You Win!"; |
20 | 20 | } else { |
21 | | - result = "You Lose!!"; |
| 21 | + result = "You Lose!"; |
22 | 22 | } |
23 | 23 | break; |
24 | | - case "paper": |
25 | | - if (compChoice === "rock") { |
26 | | - result = "You Win!!"; |
| 24 | + case "Paper": |
| 25 | + if (compChoice === "Rock") { |
| 26 | + result = "You Win!"; |
27 | 27 | } else { |
28 | | - result = "You Lose!!"; |
| 28 | + result = "You Lose!"; |
29 | 29 | } |
30 | 30 | break; |
31 | | - case "scissors": |
32 | | - if (compChoice === "paper") { |
33 | | - result = "You Win!!"; |
| 31 | + case "Scissors": |
| 32 | + if (compChoice === "Paper") { |
| 33 | + result = "You Win!"; |
34 | 34 | } else { |
35 | | - result = "You Lose!!"; |
| 35 | + result = "You Lose!"; |
36 | 36 | } |
37 | 37 | break; |
38 | 38 | } |
39 | 39 | } |
40 | | - playerDisplay.textContent = `PLAYER: ${playerChoice}`; |
| 40 | + playerDisplay.textContent = `Player: ${playerChoice}`; |
41 | 41 | compDisplay.textContent = `Computer: ${compChoice}`; |
42 | 42 | resultDisplay.textContent = result; |
43 | | - resultDisplay.classList.remove("green", "red"); |
| 43 | + resultDisplay.classList.remove("green", "red", "yellow"); |
44 | 44 | switch(result){ |
45 | | - case "You Win!!": |
| 45 | + case "You Win!": |
46 | 46 | resultDisplay.classList.add("green"); |
47 | 47 | playerScore++; |
48 | 48 | playerScoreDisplay.textContent = playerScore; |
49 | 49 | break; |
50 | | - case "You Lose!!": |
| 50 | + case "You Lose!": |
51 | 51 | resultDisplay.classList.add("red"); |
52 | 52 | compScore++; |
53 | 53 | compScoreDisplay.textContent = compScore; |
54 | 54 | break; |
| 55 | + case "It's a Tie!": |
| 56 | + resultDisplay.classList.add("yellow"); |
| 57 | + break; |
55 | 58 | } |
56 | 59 | } |
0 commit comments