Solve Project Euler #5 in Javascript 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?


Feel like I went about this the wrong way, but my gut said to check if a number divided evenly by each number up to 20 and when it did, return it.

function isDivisible(number) {
    for (d = 1; d &lt;=20; d++) {
        if (number % d === 0) {
            continue;
        } else {
            return false;
        }
    }
    return true;
}

var number = 1;
do {
    number++;
} while (! isDivisible(number));

console.log(number);
Well, it works. Better algorithms will be given in the discussion list on the Project Euler site, so I'll just look at JavaScript style.




    for (d = 1; d &lt;=20; d++) {



For consistency, there should be a space in &lt;= 20.




        if (number % d === 0) {
            continue;
        } else {
            return false;
        }



When the code skipped by continue is so short, it's more readable to invert the condition and remove the continue:

        if (number % d !== 0) {
            return false;
        }