This command will help us to create a popup box.
// Display the alert box
alert('This text is in an alert box');
Variables as we all know is used to store information.
var my_number = 2326;
var my_name = 'Welcome';
It is used to get the information from user.
var name = prompt('Please enter your name', 'Your Name');
It is used to display the output to the user,
var greet = 'Welcome ';
// Display prompt
var name = prompt('Please enter your name', 'Your name');
// Create Output Variable
var output = greet + name;
// Display Text
document.writeln('' + output + '
Using For loop
As we know for loop is used if we want to do a process n numbe rof times.
for(num=0; num < 20; num++)
Using While Loop
As we know while loops are used for repeating a pieces of code until some the condition is met. For example this code will repeat until the user enters the word 'welcome':
var password = 'welcome';
var input = prompt('Please enter the greet', '');
while(input != greet)
var input= prompt('Please enter the greet''');
Using if loop
The if function is used to check if something is true or false. For example we can check to see if text entered by a user matches a piece of text we already have (like a greet).
var num = prompt("Please enter a number between 1 and 10","");
if(num == 6)
We can call this function by following code:
<a href="#" onMouseOver="Greet();">Welcome
Function with Parameter
Parameters are a very useful part of functions. They allow us to pass data to the function when it is called. Here is an example:
in the head, then:
<a href="#" onMouseOver="Greet(Good_Morning);">GoodMorning
<a href="#" onMouseOver="say(Good_Evening);">GoodEvening