-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
32 lines (27 loc) · 1.13 KB
/
script.js
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
const computerChoice = document.getElementById('computer-choice');
const userChoice = document.getElementById('your-choice');
const Choose = document.querySelectorAll('button');
const resultDisplay = document.getElementById('verdict');
let currChoice
/* let randomNum */
let machineChoice
Choose.forEach(possibleChoice => possibleChoice.addEventListener('click',(e)=>{
currChoice = e.target.id;
userChoice.innerHTML = "Your Choice : "+ currChoice;
generateComputerChoice();
getResult();
}))
function generateComputerChoice(){
const randomNum = Math.floor(Math.random() * 3) ;
const col = ["rock", "paper","scissors"];
machineChoice = col[randomNum]
computerChoice.innerHTML = "Computer choice : " + machineChoice;
}
function getResult(){
const results = {
rock : {rock: "it's a draw", scissors : "you win!", paper: " you lost !"},
paper : {paper : "It's a draw", scissors : "you win !", rock : " you lost! "},
scissors : {scissors : "It's a draw", paper : "you win !", rock : "you loose!"}
};
resultDisplay.innerHTML = results[currChoice][machineChoice];
}