Assignment012e

JavaScript Window Object - setInterval / setTimeout and clearInterval

In this assignment you are going to get an annoying window.alert() every 3 seconds,
but the alerts will end in 10 seconds. We'll clear the setInterval() with a clearInterval() method.

<script>

// Use setInterval
var action = " window.alert('She loves me...'); ";

// Let's call our action every 3 seconds.
var myTimer =setInterval(action, 3000);

//Use the clearInterval() method
var action2 = "clearInterval(myTimer);" ;

// Let's call our action2 in fifteen seconds.
// this will turn off the setInterval named myTimer
setTimeout(action2, 15000);

</script>