본문 바로가기
Frontend/JS100 문제풀이

[JS100] 19번 문제

by 민두이 2023. 3. 29.
728x90
반응형

Q.19

공백으로 구분하여 두 숫자 a와 b가 주어지면, a의 b승을 구하는 프로그램을 작성하세요.

Answer

let getTwoNumbers = prompt('두 숫자를 입력해주세요 :-)').split(' ');

let result = getTwoNumbers[0]**getTwoNumbers[1];
console.log(result);​
let getTwoNumbers = prompt('두 숫자를 입력해주세요 :-)').split(' ');

let result = Math.pow(getTwoNumbers[0], getTwoNumbers[1]);
console.log(result);

 

 

참고 개념 : 제곱 구하기 

  • Math.pow()

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/pow

 

Math.pow() - JavaScript | MDN

The Math.pow() static method returns the value of a base raised to a power. That is

developer.mozilla.org

 

  • a**b 
728x90

'Frontend > JS100 문제풀이' 카테고리의 다른 글

[JS100] 31번 문제 (시간 복잡도)  (0) 2023.04.03
[JS100] 30번 문제  (0) 2023.04.01
[JS100] 21번 문제  (0) 2023.03.31
[JS100] 20번 문제  (0) 2023.03.30
[JS100] 18번 문제  (0) 2023.03.27