-
Notifications
You must be signed in to change notification settings - Fork 3
/
14 loops.html
47 lines (44 loc) · 1.67 KB
/
14 loops.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<html lang="en">
<head><title>Loops</title>
<!--loops are used to iterate the piece of code using for, while, do while or for/in loops.
It makes the code compact. It is mostly used in array.-->
<!--
Different Kinds of Loops
JavaScript supports different kinds of loops:
for - loops through a block of code a number of times
for/in - loops through the properties of an object
for/of - loops through the values of an iterable object
while - loops through a block of code while a specified condition is true
do/while - also loops through a block of code while a specified condition is true
-->
</head>
<body>
<script type="text/javascript">
for(var i=0;i<3;i++){
alert(i);
}
for(var i=6;i>0;i--){
//document.write(i,"<br>");
document.write("<h",i,">","Heading ",i,"</h",i,">");
}
//loops on array
var items=["EggRole","ChickenTika","FrenchFries","Pizaa","Briyani","Butter Chicken"];
for(var i=0;i<items.length;i++){
document.write("<strong>Item: ",i," = ",items[i],"<br></strong>");
//document.write("<strong>Item: ",i+1," = ",items[i],"<br></strong>"); // also try this
}
//looping on object
const products={
name:"Laptop",
brand:"HP",
Price:50000,
model:"2018"
}
let text="";
for(let x in products){
text += products[x] + ",";
}
console.log(text)
</script>
</body>
</html>