-
Notifications
You must be signed in to change notification settings - Fork 0
/
UpDown.js
33 lines (31 loc) · 905 Bytes
/
UpDown.js
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
var counter = 0;
var randomNumber = parseInt(Math.random()*100)+1;
alert(randomNumber);
function enterkey() {
if (window.event.keyCode == 13) {
finding();
}
else {
return;
}
}
function finding() {
var userNumber = document.getElementById("try").value;
if(userNumber >= 1 && userNumber <= 100){
if(randomNumber > userNumber) {
document.getElementById("disply").innerText = "UP!";
}
else if(randomNumber < userNumber) {
document.getElementById("disply").innerText = "DOWN!";
}
else if(randomNumber == userNumber) {
document.getElementById("disply").innerText = "정답!";
disply.style.color="red";
}
counter += 1;
document.getElementById("counter").innerText = `${counter}`;
}
else {
alert("1 ~ 100까지의 수만 입력하세요!");
}
}