Program to display Hello World one hundred times using JavaScript.
- We will print ‘Hello World’ 100 times using for loop.
- We will use JS DOM Manipulation to print the text.
- Click here to learn about DOM manipulation
NOTE: This requires basic JavaScript and DOM manipulation.
Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PoorWebDev</title>
</head>
<body>
<script>
for(var i=0;i<100;i++){
document.write(i + 1 + ": " + "<span>Hello, World!<span><br>");
}
</script>
</body>
</html>
Simple Example For Hello World Output two times:
Code:
<button onclick="myfun()">click me</button>
<script>
function myfun(){
for(var i=0;i<2;i++){
alert(i + 1 + ": " + "Hello, World!");
}
}
</script>