-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
70 lines (60 loc) · 2 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
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
64
65
66
67
68
69
70
//May be the current best version of myself//
const choice = ["rock", "paper", "scissors"];
var pp = document.getElementById("ppoints");
var cp = document.getElementById("cpoints");
var result = document.getElementById("result");
var psd =document.getElementById("psd");
var csd = document.getElementById("csd")
let pscore = 0;
let cscore =0;
var gr = document.getElementById("green")
function valuation(pchoice)
{
var cchoice = choice[Math.floor(Math.random()*3)];
console.log(cchoice);
pp.textContent = "Player : " + pchoice;
cp.textContent = "Computer : " + cchoice;
if(cchoice === pchoice)
{
result.textContent = "It's a TIE";
}
else
{
switch(pchoice)
{
case "rock":
result.textContent = (cchoice ==="scissors") ? "YOU WON !" : "YOU LOSE :(";
break;
case "paper":
result.textContent = (cchoice === "rock") ? "YOU WON !": "YOU LOSE :(";
break;
case "scissors":
result.textContent = (cchoice === "paper") ? "YOU WON !": "YOU LOSE :(";
break;
}
switch(result.textContent)
{
case "YOU WON !":
pscore++;
psd.textContent = pscore;
console.log(pscore);
if(pscore==5)
{
alert("You WON the match :) Start a new game")
window.location.reload();
}
break;
case "YOU LOSE :(":
cscore++;
console.log(cscore);
csd.textContent = cscore;
if(cscore== 5)
{
alert("You LOSE the match. Start a new game")
csd.textContent = cscore;
window.location.reload();
}
break;
}
}
}