JS while문 실습

tpids·2024년 6월 9일

JS

목록 보기
17/40
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 내가 입력한 숫자의 합을 구하는 프로그램
        // 0이라는 숫자를 입력하게 되면 프로그램 종료 

        let sum=0;
        let num=0;

        while(true) {
            let num = Number(prompt("숫자를 입력해주세요."));
            sum += num;

            console.log(`더한 결과:${sum}`);

            if (num===0) {
                console.log(`프로그램을 종료합니다.`);
                break;
            }            
        }
    </script>
</body>
</html>
profile
개발자

0개의 댓글