Assignment 9: A Possible Answer

This one required you think it through a bit. There had to be at least two prompt commands. One just followed the other. Then you had to variable out something that would post "My Great Page." We did it by putting that text in the title and making a variable for the "document.title" command. Then you had to variable out the "document.location".

     We put it all together in an "alert" command. This all had to be in a function and that function had to be triggered by an "onLoad" command in the BODY of the HTML document. We called our function "alertwithhello()".

     I guess you could have also created a variable for the text line, but you were only going to write it once, so we didn't feel it was really needed. Here's the script we wrote to do it.


<SCRIPT LANGAUGE="javascript">

function alertwithhello()

{

var first = prompt("What is your first name?", "")
var last  = prompt("What is you last name?", "")

var page = document.location;
var ttl = document.title;

alert("Hi " +first+ " " +last+ ".  Welcome to " 
+ttl+ ", " +page+".")

}
</SCRIPT>


And this was the BODY command from the document:

<body bgcolor="ffffcc" onLoad="alertwithhello()">

Close this window to return to JavaScript Primer #1