-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
68 lines (59 loc) · 2.26 KB
/
index.html
File metadata and controls
68 lines (59 loc) · 2.26 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
64
65
66
67
68
<!DOCTYPE html>
<html>
<head>
<title>Odin RPS</title>
</head>
<body>
<script>
// 0/1/2 for "Rock" "Paper" "Scissors"
function computerPlay(){
let i = Math.floor(Math.random()*3);
if (i == 1){
return "Rock";
}
else if (i == 2){
return "Paper";
}
return "Scissors";
}
//
function playRound(playerInput, computerInput){
if (playerInput == computerInput){
return "You've tied!"
}
// If rock, check loss, no? dubs. If paper, do same, etc.
switch(playerInput){
case "Rock":
if (computerInput == "Paper"){
return youLose(playerInput, computerInput);
}
return youWin(playerInput, computerInput);
case "Paper":
if (computerInput == "Scissors"){
return youLose(playerInput, computerInput);
}
return youWin(playerInput, computerInput);
case "Scissors":
if (computerInput == "Rock"){
return youLose(playerInput, computerInput);
}
return youWin(playerInput, computerInput);
default:
return "[" + playerInput + "] is not an acceptable option."
}
}
function youLose(you, computer){
return "You lose! Computer played: [" + computer + "] while you played: [" + you +"]."
}
function youWin(you, computer){
return "You win! Computer played: [" + computer + "] while you played: [" + you +"]."
}
function playGame(numRounds){
for (i=1; i<=numRounds; i++){
alert(playRound(prompt("Shoot!"), computerPlay()))
}
}
playGame(5);
</script>
</body>
</html>