-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJS9.html
More file actions
80 lines (59 loc) · 1.89 KB
/
JS9.html
File metadata and controls
80 lines (59 loc) · 1.89 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Loops</title>
</head>
<body>
<div class="container">
<p>This is a loop</p>
</div>
<script>
console.log('This is tutorial 8 of java script');
let i = 0;
for (i=0; i<3; i++){
console.log(i);
}
// We are using loops to itrate the array
let friends = ["Rohan","Sandip","Harsh","Harry"];
// for (let index=0; index < friends.length; index++) {
// console.log("Hello Friends," + friends[index]);
// }
// This was the old way to itrate the arry
// here is the new way easy
// friends.forEach(function fri(element){
// console.log("Hello Friend," + element + "to Mordern javascript");
// });
// You can use one more syntax for this that is for of loop
// for(element of friends){
// console.log("Hello Friend," + element + "to Mordern javascript for of loop");
// }
// These are 3 rules to itrate the array inthe javascript \
// Now we will itrate the object like
// use this loop to iterate over object in javascript for loop wrap
// let employee = {
// name: 'harry',
// age: 25,
// city:'mumbai',
// salary: 50000,
// }
// for(key in employee){
// console.log(`The ${key} and the ${employee[key]}`);
// }
// While loop in JS
let a = 0;
while(a<4){
console.log(`${a} is less than 4`);
a++;
}
// Do while loop in js
let b = 33
do{
console.log(`${b} is less than 4`);
b++;
}
while(b<4);
</script>
</body>
</html>