Internet Based Programming: Frontend Web Development
Internet Based Programming: Frontend Web Development
04/27/2025 2
1
04/27/2025
04/27/2025 3
04/27/2025 4
2
04/27/2025
04/27/2025 5
04/27/2025 6
3
04/27/2025
Operator Description
&& logical and
|| logical or
! logical no
04/27/2025 7
04/27/2025 8
4
04/27/2025
04/27/2025 9
04/27/2025 10
5
04/27/2025
04/27/2025 11
04/27/2025 12
6
04/27/2025
• The if Statement:
Syntax:
if (condition) {
// block of code to be executed if the condition is true
}
04/27/2025 13
04/27/2025 14
7
04/27/2025
04/27/2025 15
04/27/2025 16
8
04/27/2025
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Conditional Statements()</h2>
<div id="demo"></div>
<script>
let text;
if (Math.random() < 0.5) {
text = "<a href='https://www.bandirma.edu.tr/'>Visit BANU
Web Site</a>";
} else {
text = "<a href='https://mdbf.bandirma.edu.tr/tr/bil-
muh'>Visit Computer Engineering Web Site</a>";
}
document.getElementById("demo").innerHTML = text;
</script>
</body>
</html>
04/27/2025 17
04/27/2025 18
9
04/27/2025
Switch Statement: use the switch statement to select one of many code blocks to be executed.
Syntax:
switch(expression) {
case x:
// code block
break;
case y:
// code block
break;
default:
// code block
}
04/27/2025 19
Switch Statement:
<!DOCTYPE html> case 3:
<html> day = "Wednesday";
<body> break;
<h2>JavaScript switch</h2> case 4:
<p id="demo"></p> day = "Thursday";
<script> break;
let day; case 5:
switch (new Date().getDay()) { day = "Friday";
case 0: break;
day = "Sunday"; case 6:
break; day = "Saturday";
case 1: }
day = "Monday"; document.getElementById("demo").innerHT
break; ML = "Today is " + day;
case 2: </script>
day = "Tuesday"; </body>
break; </html>
04/27/2025 20
10
04/27/2025
• Switch Statement:
<body>
<h2>JavaScript switch</h2>
<p id="demo"></p>
<script>
let text;
switch (new Date().getDay()) {
case 6:
text = "Today is Saturday";
break;
case 0:
text = "Today is Sunday";
break;
default:
text = "Looking forward to the Weekend";
}
document.getElementById("demo").innerHTML = text;
</script>
</body>
04/27/2025 21
04/27/2025 22
11
04/27/2025
04/27/2025 23
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<p id="demo"></p>
const cars = [];
<script>
cars[0] = "Saab";
const cars = ["Audi", "Volvo", "BMW"];
cars[1] = "Volvo";
document.getElementById("demo").innerHTML = cars;
cars[2] = "BMW";
</script>
</body>
</html>
04/27/2025 24
12
04/27/2025
04/27/2025 25
04/27/2025 26
13
04/27/2025
04/27/2025 27
04/27/2025 28
14
04/27/2025
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<p id="p1"></p>
<script>
const fruits = ["Banana", "Orange", "Apple", "Mango"];
let fruits2 = ["Cherry", "Avocado"];
let fruits3 = ["Lime", "Coconut"];
let newfruits = fruits.concat(fruits2, fruits3);
document.getElementById("p1").innerHTML = newfruits;
</script>
</body>
</html>
04/27/2025 29
04/27/2025 30
15
04/27/2025
• indexOf(): searches an array for an element value and returns its position.
indexOf(item, start):
Item (Required): the item to search for.
Start (Optional): where to start the search.
04/27/2025 32
16
04/27/2025
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<p id="demo"></p>
<script>
const fruits = ["Apple", "Orange", "Apple", "Mango"];
let position = fruits.indexOf("Apple") + 1;
document.getElementById("demo").innerHTML = "Apple is
found in position " + position;
</script>
</body>
</html>
04/27/2025 33
04/27/2025 34
17
04/27/2025
<body>
<p id="p1"></p>
<p id="p2"></p>
<script>
const fruits = ["Banana", "Orange", "Apple", "Mango", 100, 20,]; Sorts alphabetically, in
document.getElementById("p1").innerHTML = fruits; (100, 20) pares since 1
fruits.sort(); is less than 2 it
document.getElementById("p2").innerHTML = fruits;
supposes 100 as a
</script>
</body>
string is less than 20
04/27/2025 35
<script>
const points = [40, 100, 1, 5, 25, 10];
document.getElementById("demo1").innerHTML = points;
points.sort(function (a, b) { return b - a }); Descending
document.getElementById("demo2").innerHTML = points; order
</script>
04/27/2025 36
18
04/27/2025
04/27/2025 37
04/27/2025 38
19
04/27/2025
04/27/2025 39
20