-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathStep05_example.html
55 lines (48 loc) · 1.97 KB
/
Step05_example.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Step05_example.html</title>
</head>
<body>
<h1>가위 바위 보</h1>
<select id="myPick">
<option value="0">가위</option>
<option value="1">바위</option>
<option value="2">보</option>
</select>
<button id="startBtn">시작</button>
<p id="computerPick"></p>
<script>
let data=["가위", "바위", "보"];
document.querySelector("#startBtn").addEventListener("click", function(){
// 0 or 1 or 2 중에 하나의 랜덤한 숫자 얻어내기
let ranNum=Math.floor(Math.random()*3);
//랜덤한 숫자를 data 배열의 방번호로 활용해서 com 의 패를 출력한다.
document.querySelector("#computerPick").innerText = data[ranNum];
//나의 숫자(패) 읽어오기
let myNum=Number(document.querySelector("#myPick").value);
if(myNum == ranNum){
alert("비겼습니다.");
}else if(myNum==0 && ranNum==2){
alert("이겼습니다.");
}else if(myNum==1 && ranNum==0){
alert("이겼습니다.");
}else if(myNum==2 && ranNum==1){
alert("이겼습니다.");
}else{
alert("졌습니다.");
}
});
/*
출력된 문서객체의 정보를 수정하는 작업은 웹브라우저 입장에서 약간은
무거운(시간이 살짝 걸리는) 작업니다.
따라서 해당작업은 동기로 처리 하지 않고 비동기로 처리한다.
비동기 처리도중에 alert 창이 떴고
alert 창이 뜨면 그 창이 닫아지기 전까지 웹브라우저는 아무일도 못한다.
*/
</script>
</body>
</html>