-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_updown.html
More file actions
95 lines (93 loc) · 2.51 KB
/
Copy pathexample_updown.html
File metadata and controls
95 lines (93 loc) · 2.51 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<!DOCTYPE html>
<html lang="kr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
*{
box-sizing: border-box;
}
body{
display: flex;
justify-content: center;
}
.container{
width: 300px;
height: 400px;
border: 1px solid black;
text-align: center;
}
.header,.trial{
width: 300px;
height: 35px;
font-size: 20px;
font-weight: 600;
padding: 3px;
color: white;
background-color: black;
}
.text{
width: 300px;
height: 30px;
font-size: 14px;
line-height: 3em;
}
.section{
width: 300px;
height: 150px;
padding-top: 80px;
}
.section input{
width: 100px;
height: 30px;
}
.section button{
width: 50px;
height: 30px;
}
.result{
width: 300px;
height: 150px;
padding-top: 40px;
font-size: 32px;
font-weight: 600;
}
</style>
</head>
<body>
<div class="container">
<div class="header">숫자 맞추기 게임</div>
<div class="text">1에서 100 사이의 수를 입력하세요</div>
<div class="section">
<input type="text">
<button type="button">확인</button>
</div>
<div class="result"></div>
<div class="trial"></div>
</div>
<script>
let computerNum = Math.floor(Math.random()*100)+1;
let user = document.querySelector(".section input");
let button = document.querySelector(".section button");
let result = document.querySelector(".result");
let trial = document.querySelector(".trial");
let count = 0;
button.addEventListener("click", () => {
console.log(computerNum);
let userNum = parseInt(user.value);
count++;
if(computerNum === userNum){
result.innerHTML = "Bingo!";
}
else if(computerNum > userNum){
result.innerHTML = "Up!";
}
else{
result.innerHTML = "Down!";
}
trial.innerHTML = `시도 횟수 : ${count}회`;
})
</script>
</body>
</html>