The JavaScript question
by Arnaud Buchholz
CSS
.time {
display: inline-block;
width: 100px;
color: gray;
font-size: small;
}
.time:after {
content: " ms"
}
JavaScript
[0,1,2,3,4,5,6,7,8,9].forEach(function (idx) {
setTimeout(function () {
alert(idx);
}, 1000);
});
var dtStart = new Date();
function alert(idx) {
var line = document.createElement("div"),
time = document.createElement("span"),
value = document.createElement("span");
time.className = "time";
time.innerHTML = new Date - dtStart;
value.className = "value";
value.innerHTML = idx;
line.appendChild(time);
line.appendChild(value);
document.body.appendChild(line);
}