A function is a reusable block of code that can be called anywhere in a program to perform a specific task. This avoids writing duplicate code. The example shows a function called sayHello() that displays an alert box with the text "Hello World". When the button is clicked, it calls this function. The for loop repeats a block of code a specified number of times. The example prompts the user to enter a number and uses a for loop to write "hello" to the page repeatedly if the number is over 200.
Call Girls In Mahadevapura ☎ 7737669865 🥵 Book Your One night Stand
Loops
1. Javascript- Functions
A function is a group of reusable code which can be called
anywhere in your program. This stops the need of writing the
same code again and again.
2. Copy the following code into
dreamweaver
<head> <script type="text/javascript">
function sayHello() {
alert("Hello World")
}
</script>
</head>
<body>
<input type="button" onclick="sayHello()" value="Say Hello" />
</body>
7. Javascript: for Loop
the for loop makes a list of code copy over and over.
Open a new html page and copy the following into the body tag-
<script type="text/javascript">
var bodyslam= prompt("enter a number");
bodyslam= parseFloat(bodyslam);
if (bodyslam>= 200){
for(bodyslam=5;bodyslam<=5000000;bodyslam=bodyslam+30)
document.write("<PRE>hello </PRE> ");
}
else {
alert("not a high enough number, sorry")
} </script>
The value to enter
How many times it repeats