-
Notifications
You must be signed in to change notification settings - Fork 0
/
page2.html
executable file
·89 lines (80 loc) · 3.07 KB
/
page2.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" type="text/css" href="/RPS/layout.css">
<title>Rock, Paper, Scissors</title>
<style>
*{margin:0;padding:0;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box}::selection{background:#fb9fe5;text-shadow:none}a{color:#0088CC;text-decoration:none;outline:0}a:hover{color:#005580}a img{border:none}img{max-width:100%}html{font-size:100%}body{padding:5%;font:300 1.25em/1.6 monospace;background:#fff;color:#000;}h1{font-family:"Helvetica Neue",sans-serif;line-height:1;font-weight:300;margin-bottom:1em;}.game{padding:2em;background:#eee;}
</style>
</head>
<body>
<h1>Rock, Paper, Scissors</h1>
<img src="/RPS/RPS.png" />
</br>
<div class="game">
<script>
// User choice
var userChoice = prompt("Do you choose rock, paper or scissors?");
if (! userChoice) {
// User choice was undefined
document.write("<p>Player 1, you cheated! Refresh this screen and fight like a man.</p>");
} else {
// Display user choice
document.write("<p>Player 1:" + " " + userChoice + "</p>");
}
// Computer choice
var computerChoice = Math.random();
if (computerChoice < 0.34) {
computerChoice = "rock";
} else if(computerChoice <= 0.67) {
computerChoice = "paper";
} else {
computerChoice = "scissors";
}
// Display computer choice
document.write("<p>Computer:" + " " + computerChoice + "</p>");
// Compare user choice vs computer choice
var compare = function(choice1,choice2) {
if (choice1 === choice2) {
return "It's a tie!";
}
if (choice1 === "rock") {
if (choice2 === "scissors") {
// rock wins
return "You win!";
} else {
// paper wins
return "You lose! Try again.";
}
}
if (choice1 === "paper") {
if (choice2 === "rock") {
// paper wins
return "You win!";
} else {
// scissors wins
return "You lose! Try again.";
}
}
if (choice1 === "scissors") {
if (choice2 === "rock") {
// rock wins
return "You lose! Try again.";
} else {
// scissors wins
return "You win!";
}
}
};
// Run the compare function
var results = compare(userChoice,computerChoice);
// Display results
document.write("<br><hr><br>" + results);
</script>
</div>
</br>
<a onClick="window.location.reload()" class="button">Rematch!</a>
</body>
</html>