dcsimg

Lesson 47: The Script and Its Effect



The Script

<SCRIPT LANGUAGE="JavaScript">
var states=new Array()
states[0]="CT"
states[1]="PA"
states[2]="NJ"
states[3]="NY"
states[4]="RI"

function pickstate()
{
var now=new Date()
var num=(now.getSeconds())%5
var guess=prompt("What's my favorite state: CT, PA, NJ, NY, or RI?")
if (states[num] == guess.toUpperCase())
{alert("That's my favorite state!")}
else
{alert("No, Try again")}
}

</SCRIPT>

<FORM>
<INPUT TYPE="button" VALUE="Guess My Favorite State" onClick="pickstate()">
</FORM>

 

The Script's Effect

 

Back to the Index Page