Skip to content

Commit 5d8ef98

Browse files
committed
Add HTML files for break, function, and index tutorials
1 parent b1c2bbe commit 5d8ef98

File tree

3 files changed

+165
-0
lines changed

3 files changed

+165
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Document</title>
7+
</head>
8+
<body>
9+
10+
<script>
11+
// break statement
12+
// to exit from the loop
13+
14+
for(i = 1; i <= 10; i = i + 1){
15+
if(i < 5){
16+
//break; // exit from the loop
17+
continue; // skip the current iteration
18+
}
19+
document.write(i + "<br>");
20+
}
21+
22+
23+
</script>
24+
25+
26+
</body>
27+
</html>
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Document</title>
7+
8+
<script>
9+
10+
// function
11+
// block of code
12+
// reusable code
13+
14+
// basic function
15+
function info(){
16+
alert("Hello World");
17+
}
18+
19+
// calling function
20+
//info();
21+
22+
23+
// function with parameters
24+
function get_name(name){
25+
alert("Hello " + name);
26+
}
27+
28+
// calling function with argument
29+
// get_name("Alice");
30+
31+
32+
// with return value
33+
x = 100
34+
console.log(x);
35+
36+
function x_get_value(){
37+
return 200;
38+
}
39+
40+
document.write(x_get_value());
41+
42+
// function with retun type and parameters
43+
function add_numbers(a, b){
44+
return a + b;
45+
}
46+
47+
// arrow function
48+
const info1 = () => "welcome"
49+
50+
51+
document.write(info1());
52+
53+
const get_real_name = (name) => "Hello " + name;
54+
55+
document.write(get_real_name("Charlie"));
56+
57+
58+
// return type object
59+
60+
const get_user = () => {
61+
return {
62+
name: "David",
63+
age: 30
64+
};
65+
}
66+
67+
68+
console.log(get_user());
69+
console.log(get_user().name);
70+
71+
// function with object
72+
const data = {
73+
name: "Eve",
74+
age: 25,
75+
get_details: function(){
76+
return this.name + " is " + this.age + " years old.";
77+
}
78+
}
79+
80+
console.log(data.get_details());
81+
console.log(data.name);
82+
83+
84+
</script>
85+
86+
87+
</head>
88+
<body>
89+
90+
<button onclick="info()">Click Me</button>
91+
<button onclick="get_name('Bob')">Get Name</button>
92+
93+
<h1>
94+
<script>
95+
document.write(x_get_value());
96+
</script>
97+
</h1>
98+
99+
<h1>Result : <script>
100+
101+
document.write(add_numbers(10, 20));
102+
</script></h1>
103+
104+
105+
106+
107+
</body>
108+
</html>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Document</title>
7+
8+
<script>
9+
// while loop
10+
// start point (initialization)
11+
// condition (end point)
12+
// output (body)
13+
// increment (update) / decrement (update)
14+
15+
16+
i = 1;
17+
while(i <= 10){
18+
console.log(i);
19+
i = i + 1; // increment
20+
}
21+
22+
23+
24+
</script>
25+
26+
</head>
27+
<body>
28+
29+
</body>
30+
</html>

0 commit comments

Comments
 (0)