3 visitors online
The Basic Implementation
name = prompt("What is your name","Name here");
document.write("Welcome " + name + ", to my website!");
- The 'function alert();' text defines a function, called 'alert'.
- 'name = prompt("What is your name","Name here");' defines a variable called 'name', which will be equal to the value the prompt returns.
- 'document.write("Welcome " + name + ", to my website!");' writes some text and the 'name' variable to the page.
- The <body onLoad="alert();"> tells the browser to execute the 'alert' function when the page has loaded.
Before continuing make sure you try out the code yourself and experiment with it!
age = prompt("How old are you?","21");
alert("You are " + age + " years old!);