| 39 | } |
| 40 | |
| 41 | function tallyScore(random, userPick, computerPick){ |
| 42 | //select scoreboard from DOM |
| 43 | const playerDisplay = document.querySelector('#player-score'); |
| 44 | const computerDisplay = document.querySelector('#computer-score'); |
| 45 | const winner = document.querySelector('#winner'); |
| 46 | |
| 47 | if (userPick === random){ |
| 48 | userScore++; |
| 49 | } |
| 50 | if (computerPick === random){ |
| 51 | computerScore++; |
| 52 | } |
| 53 | playerDisplay.textContent = `${userScore}`; |
| 54 | computerDisplay.textContent = `${computerScore}`; |
| 55 | |
| 56 | if (userScore === 5 && computerScore === 5){ |
| 57 | window.alert("It's a Tie"); |
| 58 | location.reload(); |
| 59 | |
| 60 | } else if (userScore === 5){ |
| 61 | window.alert("You Win!!!"); |
| 62 | location.reload(); |
| 63 | |
| 64 | } else if (computerScore === 5){ |
| 65 | window.alert("Computer Wins!!!"); |
| 66 | location.reload(); |
| 67 | |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | //add an event listener to the buttons |
| 72 | buttons.forEach(function(button){ |