-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
63 lines (58 loc) · 1.85 KB
/
Copy pathscript.js
File metadata and controls
63 lines (58 loc) · 1.85 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
let HumanScore = 0
let ComputerScore = 0
function GetComputerChoice(){
let a = Math.random()*100
if (a<33.33) {
return "Paper"
}
else if (a>66.66){
return "Rock"
}
else {
return "Scissors"
}
}
function PlayRound(player) {
let comp = GetComputerChoice()
if (comp===player) {
DisplayResult(`You both played ${player}. Its a tie!!!`)
}
else if (comp === "Rock" && player === "Paper" || comp === "Paper" && player === "Scissors" || comp === "Scissors" && player === "Rock") {
DisplayResult(`${player} beats ${comp}. You Win!!!`)
HumanScore++
}
else {
DisplayResult(`${comp} beats ${player}. You Lose!!!`)
ComputerScore++
}
DisplayPlayerScore("Your Score : " + HumanScore)
DisplayComputerScore("Computer Score : " + ComputerScore)
if (HumanScore >= 5) {
alert("Congratulations! You beat the system 🥳")
HumanScore = 0
ComputerScore = 0
DisplayPlayerScore("Your Score : " + HumanScore)
DisplayComputerScore("Computer Score : " + ComputerScore)
DisplayResult("Press a button :)")
}
else if (ComputerScore >= 5) {
alert("You got bested by this bot 😮💨. Wanna try again?")
HumanScore = 0
ComputerScore = 0
DisplayPlayerScore("Your Score : " + HumanScore)
DisplayComputerScore("Computer Score : " + ComputerScore)
DisplayResult("Press a button :)")
}
}
function DisplayResult(text) {
let display_text = document.getElementById("Text")
display_text.textContent = text
}
function DisplayPlayerScore(text) {
let display_text = document.getElementById("playerScore")
display_text.textContent = text
}
function DisplayComputerScore(text) {
let display_text = document.getElementById("computerScore")
display_text.textContent = text
}