| There are several very interesting things going on in this simple little script. You'll be able to learn quite a lot from these few lines of code.
The first line, var AskForName = prompt("Enter your name.",""); sets a new variable, var, with a name AskForName equal to the data entered in the prompt("Enter your name.",""). Notice that the prompt method has two comma separated arguments. The first argument, "Enter your name.", is what is displayed in the pop up window. The second argument will be displayed in the input area of the pop up, in this case it is blank.
The second line of code, function welcome (AskForName){, defines a new function, welcome, which uses the variable AskForName as an argument. Ths variable will be passed to the function and anywhere the AskForName occurs, the actual value of the variable, the data entered by your visitor, will be used.
The third line of the code, document.writeln("Hi "+AskForName+". Welcome to BHP"); }, uses the writeln method to write to the page the string of text enclosed in the parentheses. Note that one part of the string is the variable AskForName, the data that your visitor entered in the pop up box.
The last line of the JavaScript, welcome(AskForName), calls the function created earlier and passes to it the variable AskForName
|