Notice
Recent Posts
Recent Comments
Link
«   2025/08   »
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
관리 메뉴

기록

자바스크립트 홀짝 맞추기 (파이썬4) 본문

카테고리 없음

자바스크립트 홀짝 맞추기 (파이썬4)

9400 2023. 1. 10. 14:31
<!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 it_mine = document.querySelector("#it_mine");
	let it_com = document.querySelector('#it_com');
	let it_result = document.querySelector("#it_result");
	
	let mine = it_mine.value;
	let com="";
	
	let rnd = Math.random();
	
	if(rnd>0.5){
		com = "홀";
	}else{
		com = "짝";
	}
	
	if(mine==com) result="이겼음";
	if(mine!=com) result="졌음";

	it_com.value = com;
	it_result.value= result;
}

</script>
</head>
<body>

<table border="1">
	<tr>
		<td>나 : </td>
		<td>
			<input type="text" class="it" id="it_mine" />
		</td>
	</tr>
	<tr>
		<td>컴 : </td>
		<td>
			<input type="text" class="it" id="it_com" />
		</td>
	</tr>
	<tr>
		<td>결과 : </td>
		<td>
			<input type="text" class="it" id="it_result" />
		</td>
	</tr>
	<tr>
		<td>
			<input type="button" value="게임하기" onclick="myclick()" />
		</td>
	</tr>
</table>
</body>
</html>

출력 성공

Comments