<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel = "stylesheet" href = "../css/mystyle.css" type="text/css">
<script>
rand = parseInt(Math.random() * 100 + 1);
function proc1(){
str = "";
invalue = document.querySelector('input').value;
if(rand == invalue) str += "정답입니다";
else if(rand > invalue) str += "더 크게 입력하세요";
else str += "더 작은 수로 입력하세요";
document.querySelector('#result1').innerHTML = str;
}
function proc2(){
arr = [ "가위", "바위", "보"];
crand = parseInt(Math.random() * arr.length);
com = arr[crand];
user = prompt("가위바위보 입력");
str = "컴퓨터 : " + com + "<br>";
str += "user : " + user + "<br>";
if(com == user){
str += "비김";
}else if(user == "가위" && com == "보" ||
user == "바위" && com == "가위"||
user == "보" && com == "바위"){
str += "user 가 이김"
}else{
str += "computer가 이김";
}
document.querySelector("#result2").innerHTML = str;
}
function proc3(){
int lotte[] = new int[]
var lotto = new Array();
while(true){
rand = parseInt(Math.random() * 45 + 1);
if(lotto.indexOf(rand) == -1){
lotto.push(rand)
}
if(lotto.length >= 6) break;
}
document.querySelector("#result3").innerHTML = lotto;
}
</script>
</head>
<body>
<div class = "box">
1~100사이의 랜덤수를 발생한다<br>
발생된 랜덤 수를 입력하여 맞추기<br>
result1에는 크다 작다 힌트와 결과를 출력한다<br>
<br>
<input type="text">
<button type = "button" onclick="proc1()">확인</button>
<div id = "result1"></div>
</div>
<div class = "box">
가위 바위 보 게임을 할 수 있는 프로그램을 작성하시오. <br>
(단, 컴퓨터는 랜덤을 이용하고, 사용자는 prompt로 입력 받아서 처리)<br>
배열로 작성 arr = [ "가위", "바위", "보"]; arr[0], arr[1] arr[2] 0부터 2까지를 랜덤으로 발생시키는것
<br>
<input type="text">
<button type = "button" onclick="proc2()">확인</button>
<div id = "result2"></div>
</div>
<div class = "box">
서로중복되지 않는 정수 5개를 입력받아<br>
배열에 저장하고 출력하는 프로그램을 작성하시오<br>
<br>
<input type="text">
<button type = "button" onclick="proc3()">확인</button>
<div id = "result3"></div>
</div>
</body>
</html>