[JS 100第]問題19:平方を求める


問題19:平方を求める
2つの数字aとbをスペースで区切る場合は、aを求めるb乗のプログラムを作成します.
my solution
function squared(nums) {
  let a = nums.split(' ')[0]
  let b = nums.split(' ')[1]

  return Math.pow(a, b)
}

let nums = '2 3'
console.log(squared(nums))
答案用紙
const n = prompt('수를 입력하세요.').split(' ');

console.log(Math.pow(parseInt(n[0], 10), parseInt(n[1], 10)));
追加学習
parseInt(str, n)parseInt()は、文字列を整数に変換する関数です.stringをn進数値に置き換えます.nが入力されていない場合は、10進数で処理します.
console.log(Number.paresInt("125px")); // 125