我们需要编写一个JavaScript函数,该函数接受一个数字并根据该数字是否为正整数的事实返回一个布尔值。
完美平方数的例子-
一些完美的平方数是-
144, 196, 121, 81, 484
为此的代码将是-
const num = 484;
const isPerfectSquare = num => {
let ind = 1;
while(ind * ind <= num){
if(ind * ind !== num){
ind++;
continue;
};
return true;
};
return false;
};
console.log(isPerfectSquare(num));输出结果
控制台中的输出-
true