-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
83 lines (71 loc) · 1.91 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
var playerChoice;
var computerChoice;
var wins;
var losses;
var ties;
const roshambo = ["rock", "paper", "scissor"];
function start(){
playerChoice = null;
computerChoice = null;
wins = false
ties = false
losses = false
if (confirm("Would you like to play roshambo?")){
choice()
}else{ alert("you dont have a choice, pick again.")
start()
}
}
function choice(){
playerChoice = prompt("pick your impact device: Rock, Paper, or Scissors").toLowerCase();
if (playerChoice !== "rock" && playerChoice !== "paper" && playerChoice !== "scissor"){
alert("Pick one of the options, idiot.")
choice()
}
computerchooses()
}
function computerchooses(){
computerChoice = roshambo[Math.floor(Math.random()*3)];
console.log(computerChoice)
decideWhoWins();
}
function decideWhoWins(){
if (playerChoice === "r" && computerChoice === "s" ){
wins = true
} else if (playerChoice === "p" && computerChoice === "r" ){
wins = true
} else if (playerChoice === "s" && computerChoice === "p" ){
wins = true
} else if (playerChoice === "s" && computerChoice === "r" ){
losses = true
} else if (playerChoice === "r" && computerChoice === "p" ){
losses = true
} else if (playerChoice === "p" && computerChoice === "s" ){
losses = true
} else if (playerChoice === "p" && computerChoice === "p" ){
ties = true
} else if (playerChoice === "r" && computerChoice === "r" ){
ties = true
} else {
ties = true
}
displayOutcome();
}
function displayOutcome(){
if (ties === true){
alert("A shame. We tied... but you lose anyways.")
} else if (wins === true){
alert("Lookie lookie, you won! But you lose regardless.")
} else if (losses === true){
alert("Poor poor poor human... you lost as always...")
}
playAgain()
}
function playAgain(){
if (confirm("Would you like to play again?")){
choice()
}else{ alert("you dont have a choice, pick again.")
start()
}
}
start()