Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
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
Tags more
Archives
Today
Total
관리 메뉴

기록

자바스크립트 가위바위보 (파이썬6) 본문

JAVASCRIPT&JQUERY

자바스크립트 가위바위보 (파이썬6)

9400 2023. 1. 10. 14:34
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style>
.it{
	width : 40px;
}

</style>
<script type="text/javascript">

function myclick(){
	
	let itMine = document.querySelector("#itMine");
	let itCom = document.querySelector('#itCom');
	let itResult = document.querySelector("#itResult");
	
	let mine = itMine.value;
	let com="";
	
	let rnd = Math.random();
	
	if(rnd>0.66){
		com = "가위";
	}else if(rnd>0.33){
		com = "바위";
	}else{
		com = "보";
	}
	
	if(mine=="가위" && com=="가위") result="비김";
	if(mine=="가위" && com=="바위") result="졌음";
	if(mine=="가위" && com=="보") result="이겼음";
	
	if(mine=="바위" && com=="바위") result="비김";
	if(mine=="바위" && com=="보") result="졌음";
	if(mine=="바위" && com=="가위") result="이겼음";

	if(mine=="보" && com=="보") result="비김";
	if(mine=="보" && com=="가위") result="졌음";
	if(mine=="보" && com=="바위") result="이겼음";

	itCom.value = com;
	itResult.value= result;
}

</script>
</head>
<body>

<table border="1">
	<tr>
		<td>나 : </td>
		<td>
			<input type="text" class="it" id="itMine" />
		</td>
	</tr>
	<tr>
		<td>컴 : </td>
		<td>
			<input type="text" class="it" id="itCom" />
		</td>
	</tr>
	<tr>
		<td>결과 : </td>
		<td>
			<input type="text" class="it" id="itResult" />
		</td>
	</tr>
	<tr>
		<td>
			<input type="button" value="게임하기" onclick="myclick()" />
		</td>
	</tr>
</table>


</body>
</html>

출력성공

 

Comments