<!DOCYTPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>맛보기 예제<title>
</head>
<body>
<script>
var age = prompt("당신의 나이는?", "0");
if(age >= 20){
document.write("당신은 성인입니다");
}else{
document.write("당신은 미성년자입니다.");
}
</script>
</body>
</html>
prompt로 age값을 설정하고 if문으로 조건에 맞는 write를 출력한다.
document.write는 자바에서 System.out.print와 같은 것이다.
(참고 : do it 자바스크립트+제이쿼리 입문)
'Java Script' 카테고리의 다른 글
객체(내장객체) (1) | 2020.05.19 |
---|---|
제어문 (0) | 2020.05.19 |
연산자 (0) | 2020.05.17 |
변수 (0) | 2020.05.16 |
자바 스크립트 기초문법 (1) | 2020.05.16 |