-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
64 lines (53 loc) · 2.01 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Psychic Game</title>
<link rel="stylesheet" href="assets/css/style.css">
<link rel="stylesheet" href="assets/javascript/game.js">
</head>
<body>
<h1>The Psychic Game</h1>
<h3>Guess what letter I'm thinking of!</h3>
<h4 id="wins">Wins: </h4>
<h4 id="losses">Losses: </h4>
<h4 id="guessesLeft">Guesses Remaining: </h4>
<h4 id="guesses">Your guesses so far: </h4>
<script type="text/javascript">
var alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
var wins = 0;
var losses = 0;
var guessesLeft = 9;
var guessesSoFar = [];
var winsText = document.getElementById("wins");
var lossesText = document.getElementById("losses");
var guessesLeftText = document.getElementById("guessesLeft");
var guessesText = document.getElementById("guesses");
document.onkeyup = function (event) {
var userInput = event.key.toLowerCase();
var compAnswer = alphabet[Math.floor(Math.random() * alphabet.length)];
if (userInput === compAnswer) {
alert("You did it!")
wins ++;
guessesLeft = 9;
guessesSoFar = [];
}
if (userInput != compAnswer) {
guessesLeft --;
guessesSoFar.push(userInput);
}
if (guessesLeft === 0) {
guessesLeft = 9;
losses ++;
guessesSoFar = [];
}
winsText.textContent = "Wins: " + wins;
lossesText.textContent = "Losses: " + losses;
guessesLeftText.textContent = "Guesses Remaining: " + guessesLeft;
guessesText.textContent = " Your guesses so far: " + guessesSoFar.join(",");
}
</script>
</body>
</html>