-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
108 lines (81 loc) · 2.44 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// generates a random number and assign rock papper or scissors to it depending its value, this will be the computer's "play"
let computerPlay = "";
function getRandomNum(){
let randy = Math.floor((Math.random()*3)+1);
if (randy === 1){
computerPlay = "rock";
} else if (randy===2){
computerPlay = "paper";
}else{
computerPlay = "scissors"
}
return computerPlay
}
getRandomNum();
// -----------------
// gets user play
let win = "Computer picked rock, so you win!!"
let loose = "Computer picked rock, that means you loose!!"
let tie = "Computer picked rock too, so it's a Tie!"
let humanScore = 0;
let computerScore = 0;
// now the program
function game(){
let userPlay = window.prompt("Rock, Paper or Scissors??");
userPlay = userPlay.toLowerCase();
getRandomNum();
if(computerPlay === "rock"){
if (userPlay === "rock"){
console.log(tie)
}
else if (userPlay === "paper"){
console.log(win)
humanScore ++
}
else{
console.log(loose)
computerScore ++
}
}
else if(computerPlay === "paper"){
if (userPlay === "rock"){
console.log(loose)
computerScore ++
}
else if (userPlay === "paper"){
console.log(tie)
}
else{
console.log(win)
humanScore ++
}
}
else{
if (userPlay === "rock"){
console.log(win)
humanScore ++
}
else if (userPlay === "paper"){
console.log(loose)
computerScore ++
}
else{
console.log(tie)
}
}
}
function masterCall(){
for (i=1; i <= 5; i++){
game();
}
}
masterCall();
if (computerScore > humanScore){
console.log ('You loose :( ' + computerScore + ' to ' + humanScore)
}
else if(computerScore > humanScore){
console.log ('You win :) ' + humanScore + ' to ' + computerScore)
}
else{
console.log ("It's a Tie!!")
}