Prompting For User For Information
Prompt(prompt string, default reply)
- The prompt command requires two parameter strings.
- The first is the prompt to display, the second is the default answer.
If you do not want a default answer, just use "".
- It returns what the user typed s a string of characters
Var
- The keyword var declares a variable with the name given.
- It is not need, but is good programming style, and may prevent interpretation
problems or better error messages.
- There are two forms:
- var name;
- var name= "value";
Start A New Document In The Editor, Or cleanup the current one.
Enter the following JavaScript program
var colour = prompt("Enter favourite colour:", "Red");
document.write(colour);
Now run the program
Back