강의

멘토링

커뮤니티

Inflearn Community Q&A

rlatlahswkd3704's profile image
rlatlahswkd3704

asked

Introduction to Javascript Algorithm Problem Solving (Coding Test Preparation)

3. Number of pencils

섹션 1. 기본문제 3번

Written on

·

244

0

<html>
    <head>
        <meta charset="UTF-8">
        <title>출력결과</title>
    </head>
    <body>
        <script>
            function solution(n){
                let answer;
                let share;
                if (n === 0 ) answer = 0;
                if( n > 0 && n <= 12) answer = 1;
                else if ( n % 12 !== 0) {
                    share  = parseInt(n / 12);
                    answer = share + 1;
                }
                return answer;
            }

            console.log(solution(0));
        </script>
    </body>
</html>

위에 같이 문제를 해결하였는데 괜찮은 풀이인지 의견을 여쭤보고 싶습니다! 감사합니다.

javascript코테 준비 같이 해요!

Answer 1

0

codingcamp님의 프로필 이미지
codingcamp
Instructor

안녕하세요^^

n이 12의 배수일 때 답이 나오지 않을 것 같습니다.

 console.log(solution(24));

로 해보세요. 안나올 것 같습니다.

 

rlatlahswkd3704's profile image
rlatlahswkd3704

asked

Ask a question