dcsimg

Assignment 54: A Possible Answer

This...

<SCRIPT LANGUAGE="javascript">
var i = 0
var typeString= "All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. "
+ " All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. "
+ " All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. "
+ " All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. "

function type()
{
var stringLength= typeString.length
document.typewriterScreen.typepage.value= document.typewriterScreen.typepage.value + typeString.charAt(i)
i++
var timeID= setTimeout("type()",70)
if (i >= stringLength)
{clearTimeout(timeID); i=0; alert('done')}

}

</SCRIPT>

<BODY onLoad= "type()">

<form name="typewriterScreen">
<TEXTAREA ROWS=8 COLS=45 WRAP="virtual" NAME="typepage">
</FORM>


Gives you this...

     I got the effect of the alert box at the very end by adding the lines:

if (i >= stringLength)
{clearTimeout(timeID); i=0; alert('done')}

     ...just before the clearTimeout(TimeID) command.

     Once the count equalled the string length, the alert box popped up.

 

Did You Get It?

 

Back to the Index Page