[JS 100第]問題19:平方を求める
問題19:平方を求める
2つの数字aとbをスペースで区切る場合は、aを求めるb乗のプログラムを作成します.
my solution
parseInt(str, n)
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
Reference
この問題について([JS 100第]問題19:平方を求める), 我々は、より多くの情報をここで見つけました https://velog.io/@0seo8/문제19-제곱을-구하자テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol