-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
67 lines (56 loc) · 1.55 KB
/
script.js
File metadata and controls
67 lines (56 loc) · 1.55 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
57
58
59
60
61
62
63
64
65
66
67
//build random number for test condition
var randNum = Math.floor(Math.random() * 1000) + 1;
//test condition for randNum value as to user guess
//make enter key trigger button
// document.getElementById("userInput").addEventListener("keyup", function(event) {
// event.preventDefault();
// document.write("buffelo ")
// if (event.keyCode === 13) {
// getNumber();
// }
// });
var counter=0;
var highScore;
var counterCheck=1;
function getNumber(){
var userInput = document.getElementById("userInput").value;
var result;
if(userInput == randNum){
result = "You got it!";
}
else if(isNaN(userInput)){
result = "Please enter a number";
}
else if(userInput > 1000){
result = "Please enter a number less than 1000";
}
else if(userInput < 1){
result = "Please enter a number greater than 1";
}
else if(userInput > randNum){
result = "Too high";
}
else if(userInput < randNum){
result = "Too low";
}
else {
result = "error";
}
counter++;
highScoreUpdater();
attempts();
document.getElementById("result").innerHTML = result;
}
function highScoreUpdater(){
if(userInput == randNum){
highScore = counter;
document.getElementById("highscoreVar").innerHTML = highScore;
}
}
function attempts(){
if(userInput == randNum){
counter = 0;
randNum = Math.floor(Math.random() * 1000) + 1;
}
document.getElementById("attemptsVar").innerHTML = counter;
}