[javascript] prompt 예제
2022. 7. 18. 19:24ㆍJSP
728x90
✍️1. prompt 함수를 사용해서 등급(A,B,C)을 입력받은 후 변수에 저장, switch문으로 해당 등급을 alert 함수로 출력하기
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<script>
var grade=prompt('성적 입력(A/B/C) ');
switch(grade){
case 'A':
alert('A등급 축하합니다.');
break;
case 'B':
alert('B등급 화이팅');
break;
case 'C':
alert('C등급 분발하세요');
break;
default:
alert('잘못된 입력');
}
</script>
</body>
</html>

✍️2. 이중 for문과 document.write()를 사용해서 웹브라우저에 2~9단까지 구구단 출력하기
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>구구단</title>
<style>
div{
display : inline-block;
height: 30px;
width:90px;
color : olive;
font-size:20px;
}
</style>
</head>
<body>
<script>
for(var i=2;i<=9;i++){
document.write('<h2>'+i+'단</h2>');
for(var j=1;j<=9;j++){
document.write('<div>'+i+'x'+j+'='+ i*j+'</div>');
}
}
</script>
</body>
</html>

'JSP' 카테고리의 다른 글
[html] 예제_로그인 유효성체크 (0) | 2022.07.24 |
---|---|
[javascript] 이벤트, button, onclick, 자바스크립트에서의 함수 정의 (0) | 2022.07.18 |
[javascript]기본 입출력 alert(메세지), confirm(메세지), prompt(메세지) 또는 prompt(메세지, 기본값) (0) | 2022.07.18 |
[javascript] (0) | 2022.07.18 |
[css] <style>태그, <link> 태그 - html에서 css파일 참조하기, 선택자(selector) (0) | 2022.07.18 |