coffee ring
coffee ring

Number Machine

Whole numbers between 1 and 999999999 only!
Is Prime?

Enter a number above!

List of Divisors:

Enter a number above!

Pairs of Divisors:
Sum of Divisors:

Enter a number above!

Square Root:

Enter a number above!

Squared:

Enter a number above!

Cube Root:

Enter a number above!

Cubed:

Enter a number above!

How (Some Of) It Works

Creating the array

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]
                        
                    

Prime Numbers

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');
    }
}