Appendix JS_C_A8
Summary
Requirement: Timed activity can be controlled.
Details: Use scripting to create a blinking animation that stops in 5 seconds.
Examples
Correct code
Refer to the JS_C_A8 live demo for a working example.
<p id="demo"><strong>You have 3 new messages!</strong></p>
var text = document.getElementById('demo') .getElementsByTagName('strong').item(0); var interval = 0.5; var flashes = 0; var timer = window.setInterval(function() { if(text.style.visibility == 'hidden') { text.style.visibility = 'visible'; } else { text.style.visibility = 'hidden'; } flashes ++; if(flashes * interval == 5) { window.clearInterval(timer); } }, (interval * 1000));