JSFiddle - React, Tailwind, and code Playground
by Andrew Poes
HTML
<!-- Euler Problem 7
By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.
What is the 10 001st prime number? -->
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 found = 10001
var count = 1
while (found > 0) {
++count
if (isPrime(count)) {
--found
}
}
print("last prime", count)
})
function isPrime(num) {
if (num < 2) {
return false
}
// Prime numbers other than two are odd...
if (num == 2) {
return true
}
else if (num%2 == 0) {
return false
}
// Check it isn't divisible by up to its square root
// (consider n=(root n)(root n) as factors)
for (var i = 3; i <= Math.sqrt(num); ++i) {
if (num%i == 0) {
return false
}
}
return true
}
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
}