-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
56 lines (45 loc) · 1.04 KB
/
Copy pathscript.js
File metadata and controls
56 lines (45 loc) · 1.04 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
//choices
var words = [
"frame",
"fork",
"handlebar",
"shifter",
"chain",
"derailleur",
"brakes",
"tire",
"tube",
"wheel",
];
// Random Word
var word = words[Math.floor(Math.random() * words.length)];
// Answer Array
var answerArray = [];
for (var i = 0; i < word.length; i++) {
answerArray[i] = "*";
}
var remainingLetters = word.length;
// Game
while (remainingLetters > 0) {
// Game Progress
alert(answerArray.join(" "));
// Choose a word
var guess = prompt("Guess a letter, or click Cancel to stop the game.");
if (guess === null) {
// End
break;
} else if (guess.length !== 1) {
alert("Please enter a single letter.");
} else {
// Update the game state with the guess
for (var j = 0; j < word.length; j++) {
if (word[j] === guess) {
answerArray[j] = guess;
remainingLetters--;
}
}
}
}
// Final alert
alert(answerArray.join(" "));
alert("Good job! The answer was " + word);