Internet Based Programming: Frontend Web Development
Internet Based Programming: Frontend Web Development
04/20/2025 2
1
04/20/2025
<!DOCTYPE html>
<html>
<body>
<h2>What Can JavaScript Do?</h2>
<p id="demo">JavaScript can change HTML content.</p>
<button type="button"
onclick='document.getElementById("demo").innerHTML =
"Hello JavaScript!"'>Click Me!</button>
</body>
</html>
04/20/2025 3
04/20/2025 4
2
04/20/2025
<!DOCTYPE html>
<html>
<body>
<h2>What Can JavaScript Do?</h2>
<p id="demo">JavaScript can change
the style of an HTML element.</p>
<button type="button"
onclick="document.getElementById('demo'
).style.fontSize='35px'">Click
Me!</button>
</body>
</html>
04/20/2025 5
<!DOCTYPE html>
<html>
<body>
<h2>What Can JavaScript Do?</h2>
<p id="demo">JavaScript can hide HTML elements.</p>
<button type="button"
onclick="document.getElementById('demo').style.display='none'">
Click Me!</button>
</body>
</html>
04/20/2025 6
3
04/20/2025
<!DOCTYPE html>
<html>
<body>
<h2>What Can JavaScript Do?</h2>
<p id="demo" style="display:none">Hello
JavaScript!</p>
<button type="button"
onclick="document.getElementById('demo').style.
display='block'">Click Me!</button>
</body>
</html>
04/20/2025 7
04/20/2025 8
4
04/20/2025
04/20/2025 9
5
04/20/2025
• JavaScript in Body Section: we can write JavaScript code anywhere in the body section.
In HTML, JavaScript code is inserted between <script> and </script> tags.
A document can have one or more scripts depending on what and when we want to do something
through JavaScript.
If a JavaScript is not bound to any event, it will always execute when we load the page.
The script that is bound to an event executes only when the specified event happens.
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript in Body</h2>
<script>
document.write("My First JavaScript");
</script>
</body>
</html>
04/20/2025 11
• JavaScript in Body Section: we can write JavaScript code anywhere in the body section.
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript in Body</h2>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = "My First JavaScript";
</script>
</body>
</html>
04/20/2025 12
6
04/20/2025
• JavaScript in Head Section: a special place for the <script> element is within the head section
of a document.
<!DOCTYPE html>
<html>
<head>
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "Paragraph changed.";
}
</script>
</head>
<body>
<h2>Demo JavaScript in Head</h2>
<p id="demo">A Paragraph.</p>
<button type="button" onclick="myFunction()">Try it</button>
</body>
</html>
04/20/2025 13
04/20/2025 14
7
04/20/2025
• Notes:
You can place any number of scripts in an HTML document.
You have to nocte the sequence of operations, for example if you write a script to
change the content of an element before creating of that element the script will not
work.
Placing scripts at the bottom of the <body> element improves the display speed,
because script interpretation slows down the display.
04/20/2025 15
<!DOCTYPE html>
<html>
<body>
<h2>Demo JavaScript in Body</h2>
<p id="demo">Paragraph not changed.</p>
<script>
document.getElementById("demo").innerHTML = "Paragraph changed.";
</script>
</body>
</html>
04/20/2025 16
8
04/20/2025
• External JavaScript: the code is saved in a separate file (e.g., myScript.js) which is then linked to
an HTML document using src attribute of <script> tag.
anHTMLDocument.html
<!DOCTYPE html>
<html>
<body>
<h2>Demo External JavaScript</h2>
<p id="demo">A Paragraph.</p>
<button type="button" onclick="myFunction()">Try it</button>
<script src="myScript.js"></script>
</body>
</html>
myScript.js
function myFunction() { External scripts cannot
document.getElementById("demo").innerHTML = "Paragraph changed.";
contain <script> tags.
}
04/20/2025 17
• External JavaScript: you can place an external script reference in <head> or <body> as you like.
anHTMLDocument.html
<!DOCTYPE html>
<html>
<head>
<script src = "myScript.js"></script>
</head>
<body>
<h2>Demo External JavaScript</h2>
<script>
document.write("Script demo");
</script>
<button type="button" onclick="msg();">click</button>
</body>
</html>
myScript.js
function msg() { alert('You clicked on the button');}
04/20/2025 18
9
04/20/2025
04/20/2025 19
<!DOCTYPE html>
<html>
<body>
<h2>innerHTML:</h2>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = 5 + 6;
</script>
</body>
</html>
04/20/2025 20
10
04/20/2025
04/20/2025 21
04/20/2025 22
11
04/20/2025
04/20/2025 23
04/20/2025 24
12
04/20/2025
04/20/2025 25
04/20/2025 26
13
04/20/2025
04/20/2025 27
04/20/2025 28
14
04/20/2025
04/20/2025 29
• Examples:
// Numbers: // Object:
let length = 16; const person = { firstName: “Inan", lastName: “Kazanci" };
let weight = 7.5;
// Array object:
// Strings: const cars = ["Audi", "Volvo", "BMW"];
let color = "Yellow";
let lastName = “Kazanci"; // Date object:
const date = new Date("2022-03-25");
// Booleans
let x = true;
let y = false;
04/20/2025 30
15
04/20/2025
• You can use single or double quotes with strings. Also, You can use quotes inside a string, as long as they don't
match the quotes surrounding the string.
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
let x = "String:";
let y = "University 'BANU'";
let z = 'University "BANU"';
document.getElementById("demo").innerHTML = x + "<br>" + y + "<br>" + z;
</script>
</body>
</html>
04/20/2025 31
04/20/2025 32
16
04/20/2025
04/20/2025 33
04/20/2025 34
17
04/20/2025
04/20/2025 35
04/20/2025 36
18
04/20/2025
04/20/2025 37
04/20/2025 38
19
04/20/2025
04/20/2025 39
04/20/2025 40
20
04/20/2025
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
let a = "We Love";
let b = "JavaScript";
let c = "And";
let d = "Programming";
document.getElementById("demo").innerHTML = (`${a} "${b} ${c}' ${d}"`);
</script>
</body>
</html>
04/20/2025 41
04/20/2025 42
21
04/20/2025
04/20/2025 43
04/20/2025 44
22
04/20/2025
04/20/2025 45
<body>
<p id="demo"></p>
<script>
let title = "BANU:";
let desc = "Bandirma Onyedi Eylul University";
let markup =
`<div class="card">
<div class="child">
<h2>${title}</h2>
<p>${desc}</p>
</div>
</div>`;
document.write(markup);
</script>
</body>
</html>
04/20/2025 46
23
04/20/2025
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
let title = "BANU:";
let desc = "Bandirma Onyedi Eylul University";
These are at let markup = "<div class=\"card\">\n<div
the same line class=\"child\">\n<h2>".concat(title,"</h2>\n<p>").concat(desc,"</p>\n</div>\n</div>");
document.write(markup);
</script>
</body>
</html>
04/20/2025 47
04/20/2025 48
24