Enter a number above!
Enter a number above!
Enter a number above!
Enter a number above!
Enter a number above!
Enter a number above!
Enter a number above!
This function checks whether the input
value can be divided by the current iteration [i]
without leaving
a remainder - if it can, then the number [i]
is added on to the end of an array named total
.
const divCalculator = (input) => {
let total = [];
for (let i = 1; i <= input; i++) {
if (input % i === 0) {
total.push(i);
};
};
return total;
}
// if inputValue is 12, total = [1, 2, 3, 4, 6, 12]
// if inputValue is 319, total = [1, 11, 29, 319]
This function checks to see if the input
value is a prime number.
Inputting 1 and 2 will simply return "False" and "True" respectively but for any number greater than 2, if it can be divided by the current iteration [i]
,
it won't be a prime number, so the output is false.
const testPrime = (input) => {
if ( input === 1 ) {
return ('false');
} else if ( input === 2 ) {
return ('true');
} else {
for ( let i = 2; i < input; i++ ) {
if ( input % i === 0 ) {
return ('false');
}
}
return ('true');
}
}