별초롱언니 2025. 4. 3. 11:03

01. 개념

if문 안에 if문을 또 사용하는 것

 

02. 사용법

if (조건식) {

   if (조건식) {

 

   }

}

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>중첩된 if문</title>
</head>

<body>
  <script>
    var score = Number(prompt("학생 점수를 입력하세요", "0~100 사이의 정수"));

    if (score >= 0 && score <= 100) {
      if (score > 80) {
        alert("합격");
      } else {
        aleft("불합격");
      }
    } else {
      alert("0~100사이의 정수로 입력하세요");
    }
  </script>
</body>

</html>