JSFiddle - React, Tailwind, and code Playground

by Andrew Poes

HTML

<!-- Euler Problem 5

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? -->

CSS

.print {
    position: relative;
    display: inline-block;
    background-color: black;
    color: white;
    font-family: Helvetica, Helvetica-Neue, sans-serif;
    font-weight: bold;
    font-size: 24px;
    letter-spacing: -1.5px;
    padding: 4px 8px;
}

body {
    background-color: #eeeeee;
}
}

JavaScript

$(document).ready(function() {
    var value = 10;
    var found = false;
    var checkmax = 20;
    while (!found) {
        var checksout = true;
        for (var i = checkmax; i > 0; --i) {
            if (value%i != 0) {
                checksout = false;
                break;
            }
        }
        if (checksout) {
            found = true;
            print(value);
        }
        else {
            ++value;
            if (value > 1000000000) {
                found = true;
                print("did something wrong");
            }
        }
    }
})

function print() {
    var args = Array.prototype.slice.apply(arguments)
    var str = ""
    for (arg of args) {
        str += arg + ", "
    }
    str = str.substring(0, str.length - 2)
    var el = newel(str)
    $("body").append(el)
    $("body").append("</br>")
}

function newel(str) {
    var el = document.createElement("div")
    $(el).html(str)
    $(el).addClass("print")
    return el
}