[구디아카데미][IT국비지원][TIL] 주사위 던지기

Seokhyun Jeong·2023년 4월 19일
0

과제

목록 보기
4/19
post-thumbnail

[구디아카데미][IT국비지원]

코드

dice.html

<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>Insert title here</title>
</head>
<body>
	<div style="text-align: center">
		<image src="./img/ready.jpg" width="200" height="200">
		<image src="./img/ready.jpg" width="200" height="200">
		<div>
			<a href="./diceResult.jsp">start</a>
		</div>
	</div>
</body>
</html>

diceResult.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>Insert title here</title>
</head>
<body>
	<%
		int d1 = 0; // 1~6
		int d2 = 0; // 1~6
		
		d1 = (int) (Math.random() * 6) + 1;
		d2 = (int) (Math.random() * 6) + 1;
		
		int sum = d1 + d2;
	%>
	<div style="text-align: center">
		<%
			if (d1 == 1) {
				%>
					<image src="./img/1.jpg" width="200" height="200">
				<%
			} else if (d1 == 2) {
				%>
					<image src="./img/2.jpg" width="200" height="200">
				<%
			} else if (d1 == 3) {
				%>
					<image src="./img/3.jpg" width="200" height="200">
				<%
			} else if (d1 == 4) {
				%>
					<image src="./img/4.jpg" width="200" height="200">
				<%
			} else if (d1 == 5) {
				%>
					<image src="./img/5.jpg" width="200" height="200">
				<%
			} else {
				%>
					<image src="./img/6.jpg" width="200" height="200">
				<%
			}
		
			if (d2 == 1) {
				%>
					<image src="./img/1.jpg" width="200" height="200">
				<%
			} else if (d2 == 2) {
				%>
					<image src="./img/2.jpg" width="200" height="200">
				<%
			} else if (d2 == 3) {
				%>
					<image src="./img/3.jpg" width="200" height="200">
				<%
			} else if (d2 == 4) {
				%>
					<image src="./img/4.jpg" width="200" height="200">
				<%
			} else if (d2 == 5) {
				%>
					<image src="./img/5.jpg" width="200" height="200">
				<%
			} else {
				%>
					<image src="./img/6.jpg" width="200" height="200">
				<%
			}
		%>
	</div>
	<div style="text-align: center">주사위 결과 : <%=sum %></div>
</body>
</html>

결과화면


0개의 댓글