woojin,
<div id="timer"></div>
<script>
var answerTimer = {
timerAnswer: 0,
answerTimerId: null,
timer: function () {
this.toPrint();
++this.timerAnswer;
var self = this;
this.answerTimerId = setTimeout(function() {
self.timer()
}, 1000);
},
reset: function () {
this.timerAnswer = 0;
},
stop: function () {
this.reset();
clearTimeout(this.answerTimerId);
},
toPrint: function () {
document.getElementById("timer").innerHTML = "last answer: " + this.timerAnswer + " sec";
}
};
answerTimer.timer();
setTimeout(function() {
answerTimer.stop()
}, 5054);
</script>