-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgames.html
More file actions
34 lines (31 loc) · 734 Bytes
/
games.html
File metadata and controls
34 lines (31 loc) · 734 Bytes
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Math</title>
</head>
<body>
<script type="text/javascript">
var x = Math.ceil(Math.random() * 100);
var turns = 5;
var hint = 'Guess my number, 1-100!';
while (turns > 0) {
var guess = prompt(hint +
' You have ' + turns + ' guesses left.');
if (!guess) break;
guess = Number(guess);
if (guess == x) {
document.write('<p>YOU WIN!</p>' +
'<p><img src="/images/ohoto/gold_trophy.jpg">');
turns = 0;
} else {
hint = 'nope';
if (guess < x) hint += ' Too small!';
if (guess > x) hint += ' Too big!';
turns = turns -1;
}
}
alert('The secret number was ' + x + '.');
</script>
</body>
</html>