인프런 영문 브랜드 로고
인프런 영문 브랜드 로고

Inflearn Community Q&A

odreystelladev2446's profile image
odreystelladev2446

asked

Easy and Natural Javascript Introduction - Code Squad Masters Course Level 1

Coding Implementation - Steps 4 and 5

안녕하세요 선생님, 질문있습니다.

Resolved

Written on

·

159

1

안녕하세요, 

마지막에 내주신 <h1>구구단 X단 구현</h>부분을 과제로 내주셔서 방법을 찾아봤는데요..

되게 이상하게 짠거 같은데 이렇게 밖에 구현을 못했습니다.

원했던 건 몇 단을 출력할지 입력받은 n 변수를 사용하고 싶었는데 스크립트 바깥에 있는 부분이라 원하는대로 안나오더라구요ㅜ 더 효율적인 코드가 있을까요?

<body>
    <script>
        var n = Number(prompt(" 몇 단을 출력할까요"));
        document.write("<h1>구구단" + n + "단 구현</h1>");

        var n = Number(prompt("몇 단을 출력할까요?."));
        document.write(n + "단<br>");
        console.log(n + " * 1 = " + n * 1);        
        console.log(n + " * 2 = " + n * 2);        
        console.log(n + " * 3 = " + n * 3);        
        console.log(n + " * 4 = " + n * 4);        
        console.log(n + " * 5 = " + n * 5);        
        console.log(n + " * 6 = " + n * 6);        
        console.log(n + " * 7 = " + n * 7);        
        console.log(n + " * 8 = " + n * 8);        
        console.log(n + " * 9 = " + n * 9); 
javascript

Answer 1

0

honux님의 프로필 이미지
honux
Instructor

안녕하세요? 일단 완성하신 걸로 의의를 두셔도 좋을 것 같아요. 반복문을 적용하시면 더 깔끔하게 짤 수 있습니다.

odreystelladev2446's profile image
odreystelladev2446

asked

Ask a question