JSFiddle - React, Tailwind, and code Playground

by Andrew Poes

HTML

<!-- Euler Problem 6
//The sum of the squares of the first ten natural numbers is,

//1^2 + 2^2 + ... + 10&2 = 385
//The square of the sum of the first ten natural numbers is,

//(1 + 2 + ... + 10)^2 = 55^2 = 3025
//Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 − 385 = 2640.

//Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum. -->

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 sumOfSquare = 0
    var sum = 0
    for (var i=1; i <= 100; ++i) {
        sumOfSquare += Math.pow(i,2)
        sum += i
    }
    sum = Math.pow(sum,2)
    print("sum1", sumOfSquare)
    print("sum2", sum)
    print("delta", sum - sumOfSquare)
})

function str(num) {
    return num.toString()
}

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
}