-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathJokes.js
29 lines (27 loc) · 1.15 KB
/
Jokes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
function DisplayText(num, elem) {
var num = prank(num);
elem.innerHTML = "";
var tab = document.createElement("table");
tab.style.width = "100%";
var row = tab.insertRow(0);
var out1 = row.insertCell(0);
var out2 = row.insertCell(1);
out1.style.fontSize = "0.5em";
out1.innerHTML = num.m;
out2.innerHTML = num.e;
out2.style.fontSize = (window.getComputedStyle(elem, null).getPropertyValue("font-size").replace("px", "") / Math.pow(2,Math.log(num.e.length)/1.8)) + "px";
out2.style.lineHeight = (window.getComputedStyle(elem, null).getPropertyValue("font-size").replace("px", "") / Math.pow(2, Math.log(num.e.length)/1.8)) + "px";
elem.appendChild(tab);
}
function prank(num) {
var stuff = [" Sup", " nerd,", " you", " have", " been", " pranked!", " Happy", " April", " fools", " 2018!"]
if (num >= Number.MAX_VALUE) return "Infinity";
var digits = Math.floor(Math.max(Math.log10(num),0));
var temp = {};
temp.m = (num / Math.pow(10, digits)).toFixed(1) + (num>=10?"e":"");
temp.e = "";
for (var i = 0; i < digits; i++) {
temp.e = temp.e + stuff[i % 10];
}
return temp;
}