-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrock-paper-scissor.js
83 lines (75 loc) · 1.99 KB
/
rock-paper-scissor.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
71
72
73
74
75
76
77
78
79
80
81
82
83
let score=JSON.parse(localStorage.getItem('score'))
if(!score){
score={
Win:0,
Loose:0,
Tie:0
};
}
updateScore()
function function1(){
let Comnputermove='';
Comnputermove=Math.random();
if(Comnputermove>=0 && Comnputermove<1/3){
Comnputermove='rock'
}
else if(Comnputermove>=1/3 && Comnputermove<2/3){
Comnputermove='paper'
}
else if(Comnputermove>2/3 && Comnputermove<1){
Comnputermove='scissors'
}
return Comnputermove;
}
function updateScore(){
document.querySelector('.js-score').innerHTML=`win: ${score.Win} Loose: ${score.Loose} Tie: ${score.Tie}`;
}
function function2(playermove){
let result='';
if(playermove==='rock'){
if(Comnputermove==='rock'){
result='Tie'
}
else if(Comnputermove==='paper'){
result='You Loose'
}
else if(Comnputermove==='scissors'){
result='You Win'
}
}
else if(playermove==='paper'){
if(Comnputermove==='rock'){
result='You Win'
}
else if(Comnputermove==='paper'){
result='Tie'
}
else if(Comnputermove==='scissors'){
result='You Loose'
}
}
else if(playermove==='scissors'){
if(Comnputermove==='rock'){
result='You Loose'
}
else if(Comnputermove==='paper'){
result='You Win'
}
else if(Comnputermove==='scissors'){
result='Tie'
}
}
if(result==='You Win'){
score.Win+=1;
}
else if(result==='You Loose'){
score.Loose+=1;
}
else if(result=='Tie'){
score.Tie+=1;
}
localStorage.setItem('Score',JSON.stringify(score));
updateScore()
document.querySelector('.js-result').innerHTML=result;
document.querySelector('.js-compare').innerHTML=`You <img src="${playermove}-emoji.png" class="image"> <img src="${Comnputermove}-emoji.png" class="image"> Computer`;
}