because
setTimeout(function() {
document.getElementById('p').innerHTML = "2";
}, 4000);
setTimeout(function() {
document.getElementById('p').innerHTML = "3";
}, 4000);
setTimeout(function() {
document.getElementById('p').innerHTML = "4";
}, 4000);
};
are editing the same element so you see only the result of the last operation: 4
The setTimeout()
method calls a function or evaluates an expression after a specified number of milliseconds.
and in your case the time is same, so all executed at same time.
set some interval between them.