...

/

Solution Review: Lint the Code

Solution Review: Lint the Code

Learn how to solve the problem in the previous lesson.

We'll cover the following...

Solution

Let’s take a look at the solution code given below.

Press + to interact
'use strict';
const isPerfect = function(number) {
let sumOfFactors = 0;
for(let index = 1; index <= number; index++) {
if(number % index === 0) {
sumOfFactors += index;
}
}
return sumOfFactors === number * 2;
};
for(let i = 1; i <= 10; i++) {
console.log('is ' + i + ' perfect?: ' + isPerfect(i));
}

Explanation

  • First of all, use strict; is applied to the code to make the code secure.

  • In ...

Access this course and 1400+ top-rated courses and projects.