programming-examples/js/Functions/Write a JavaScript function which says whether a number is perfect..js

21 lines
442 B
JavaScript
Raw Normal View History

2019-11-15 12:59:38 +01:00
function is_perfect(number)
{
var temp = 0;
for(var i=1;i<=number/2;i++)
{
if(number%i === 0)
{
temp += i;
}
}
if(temp === number && temp !== 0)
{
console.log("It is a perfect number.");
}
else
{
console.log("It is not a perfect number.");
}
}
is_perfect(28);