---
# System prepended metadata

title: 6/26 과제

---

# 6/26 과제

## 문제 1
```
    <h1>음수양수판별</h1>
    <div id="result"></div>
    <script>
        function userInput() {
            let userNum = prompt("숫자를 입력하시오")
            userNum >= 0
                ? document.getElementById("result").innerText = "양수"
                : document.getElementById("result").innerText = "음수"
        }

        userInput();
    </script>
```

## 문제 1_변형 : 입력받은 값이 숫자가 아닐경우는 숫자일 때까지 계속 입력받음
```
<h1>음수양수판별</h1>
    <div id="result"></div>
    <script>
        function userInput() {
            let userNum = prompt("숫자를 입력하시오")
            return Number(userNum)
        }

        function isPositive() {
            let userNum = userInput()
            console.log(userNum)
            while (isNaN(userNum)) {
                userNum = userInput()
            }

            userNum >= 0
                ? document.getElementById("result").innerText = "양수"
                : document.getElementById("result").innerText = "음수"
        }

        isPositive();
    </script>
```

## 문제 2
```
<h1>당신의 레포트 성적</h1>
    <div id="score"></div>

    <script>
        let yourScore = prompt("당신의 레포트 점수를 입력하시오")
        yourScore = Number(yourScore)
        let yourGrade;
        if (yourScore >= 90 && yourScore <= 100) {
            yourGrade = "A"
        } else if (yourScore >= 80 && yourScore < 90) {
            yourGrade = "B"
        } else if (yourScore >= 70 && yourScore < 80) {
            yourGrade = "C"
        } else if (yourScore >= 60 && yourScore < 70) {
            yourGrade = "D"
        } else {
            yourGrade = "F"
        }
        document.getElementById("score").innerText = yourGrade
    </script>
```

## 문제 3
```
<h1>당신이 사용 가능한 스킬을 체크하시오</h1>
    <form>
        <label for="ability1"><input type="checkbox" id="ability1" value="HTML" /> HTML</label>
        <label for="ability2"><input type="checkbox" id="ability2" value="CSS" /> CSS</label>
        <label for="ability3"><input type="checkbox" id="ability3" value="Javascript" /> Javascript</label>
        <label for="ability4"><input type="checkbox" id="ability4" value="React" /> React</label>
    </form>
    <button onClick="getResult()">합격여부체크</button>
    <h2>결과</h2>
    <div id="result"></div>

    <script>
        let result = document.getElementById("result")
        function getResult() {
            const checkboxes = document.querySelectorAll('input[type="checkbox"]');
            let checkList = []
            checkboxes.forEach((item) => {
                if (item.checked) {
                    checkList.push(item.value)
                }
            })
            console.log('체크된리스트', checkList)
            const arrPass = ["HTML", "CSS", "Javascript", "React"]
            const arrSpair = ["HTML", "CSS", "Javascript"]

            if (arrPass.every(item => checkList.includes(item))) {
                result.innerText = "합격"
            } else if (arrSpair.every(item => checkList.includes(item))) {
                result.innerText = "예비"
            } else {
                result.innerText = "탈락"
            }
        }
    </script>
```