-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrockPaperScissors.html
More file actions
68 lines (59 loc) · 2.29 KB
/
rockPaperScissors.html
File metadata and controls
68 lines (59 loc) · 2.29 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 lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="author" content="Adolfo Barrientos">
<title>Rock Paper Scissors</title>
<script>
function rockPaperScissors(form){
console.log("Console works!")
let p1 = (document.getElementById("p1").value.toLowerCase());
let p2 = (document.getElementById("p2").value.toLowerCase());
console.log("Player 1 used " + p1)
console.log("Player 2 used " + p2)
//Checks p1 and p2
if(p1 === 'rock' || p1 === 'paper' || p1 === 'scissors'){
console.log("p1 check passed!")
}else{
if(p2 === 'rock' || p2 === 'paper' || p2 === 'scissors'){
console.log("p2 check passed!")
}else{
form.reset();
console.log("Invalid move of Player 1 " + p1)
return console.log("Invalid move of Player 2 " + p2)
}
form.reset();
return console.log("Invalid move of Player 1 " + p1)
}
//checks p2
if(p2 === 'rock' || p2 === 'paper' || p2 === 'scissors'){
console.log("p2 check passed!")
}else{
form.reset();
return console.log("Invalid move of Player 2 " + p2)
}
//conditions to win
if (p1 != p2){
if(p1 == "rock" && p2 == "scissors" ||
p1 == "scissors" && p2 == "paper" ||
p1 == "paper" && p2 == "rock"){
console.log("player 1 wins!")
}else console.log("player 2 wins!")
form.reset();
}else if(p1 == p2) {
form.reset();
return console.log("it's a TIE!")
}
form.reset();
}
</script>
</head>
<body>
<form>
Player 1: <input type="text" id="p1" placeholder="Rock, Paper, Scissors"><br>
Player 2: <input type="text" id="p2" placeholder="Rock, Paper, Scissors"><br><br>
<button type="button" onclick="rockPaperScissors(this.form);" >Click Me!</button>
</form>
</body>
</html>