JSFiddle - React, Tailwind, and code Playground

by ktstowell

HTML

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?

JavaScript

var base = 2520,
    div = 21,
    exec = true,
    ans;

while(exec) {
    var isDivisible;
    innerLoop:
    for(var i=1; i<div; i++) {
        if(base % i !== 0) {
            isDivisible = false;
            break innerLoop;
        } else {
            isDivisible = true;
        }
    }
    
    if(isDivisible) {
        exec = false;
        ans = base;
    } else {
        base++;
    }
}

console.log(ans)