// This program displays date and time methods.
//
// References:
// https://en.wikibooks.org/wiki/JavaScript
"use strict";
window.addEventListener("load", function () {
document.getElementById("date").addEventListener("change", inputChange);
window.setInterval(timerInterval, 1000);
document.getElementById("code1-button").addEventListener("click", code1Click);
document.getElementById("code2-button").addEventListener("click", code2Click);
});
function inputChange() {
let value = document.getElementById("date").value;
let date = new Date(value);
let iso = date.toISOString();
document.getElementById("iso").innerText = iso;
let utc = date.toUTCString();
document.getElementById("utc").innerText = utc;
}
function timerInterval() {
let now = Date.now();
document.getElementById("now").innerText = now +
" (milliseconds since January 1, 1970)";
}
function code1Click() {
let start = Date.now();
let result = "";
// loop one million times
for (let i = 0; i < 1000; i++) {
for (let j = 0; j < 1000; j++) {
result = i * j;
}
}
document.getElementById("code1").innerText = result;
let elapsed = Date.now() - start;
document.getElementById("code1").innerText = elapsed;
}
function code2Click() {
let start = Date.now();
// loop one million times
for (let i = 0; i < 1000; i++) {
for (let j = 0; j < 1000; j++) {
document.getElementById("code2").innerText = i * j;
}
}
let elapsed = Date.now() - start;
document.getElementById("code2").innerText = elapsed;
}