-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
42 lines (32 loc) · 1.02 KB
/
index.html
File metadata and controls
42 lines (32 loc) · 1.02 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
<html>
<head>
<meta charset="UTF-8">
<title>physic game</title>
</head>
<body>
<div id="game">
<p>Guess what letter i am thinking of</p>
</div>
<script type="text/javascript">
document.write("Physic Game")
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;
document.onkeyup = function(){
var userguess = String.fromCharCode(event.keyCode).toLowerCase();
console.log(userguess);
var computerGuess = alphabet[Math.floor(Math.random()*alphabet.length)];
console.log(computerGuess);
if(computerGuess == userguess){
alert("wins: "+ wins);
}else{
alert("losses:"+ losses);
};
var letterToGuess;
var letterGuessed;
var html="<p>Press any key to guess letter i am thinking of.</p>"+"<p>wins: " + wins + "</p>"+"<p>losses: "+losses + "</p>"+"<p>Your guesses so far: "+letterGuessed+"</p>"+"<p>Guesses left: "+letterToGuess+"</P>"
document.querySelector("#game").innerHTML=html;
}
</script>
</body>
</html>