B) Properties (often nicer)
C) Custom data: data-* + dataset
8) Forms + validation basics (DOM side)
✅ Uses built-in HTML validation + DOM for feedback.
9) When should your JS run? (DOMContentLoaded, defer)
Option A: Put <script> at the end of <body>
HTML loads first → then script runs (elements exist).
Option B: Use defer in the head
defer waits until HTML is parsed, then runs script.
Option C: Listen for the DOM to be ready
10) Mini build (step-by-step): Add items to a list + remove items
(Just a teaching demo; not a “challenge”)
What you practiced here:
➤submit + preventDefault()
➤createElement / appendChild / append
➤event.target and delegation on the <ul>
11) Good habits & small gotchas
✅Prefer addEventListener over inline events.
✅Use textContent for text; innerHTML only when you must render HTML (never with untrusted input).
✅Prefer classes (classList) over inline styles.
✅Use defer or run code after DOMContentLoaded.
✅When attaching many handlers to many children, prefer event delegation on their parent.
✅Keep HTML semantic & accessible (use <button> for clickables, connect <label> with for to inputs, etc.).
🧠 Today you learned
✅The right way to handle events with addEventListener (and how to remove them).
✅The event object and how to use event.target.
✅The difference between input / change / submit / keyboard & mouse events.
✅Creating, inserting, cloning, and removing elements.
✅classList, attributes vs properties, and custom data- attributes.
✅How to organize scripts so the DOM exists when your code runs.
🔥🔥You just unlocked the power to build real interactive pages. 🚀
const img = document.querySelector('img');
img.src = 'cat.jpg';
img.alt = 'A cute cat'; C) Custom data: data-* + dataset
<button id="pay" data-plan="pro" data-price="299">Buy</button>
<script>
const pay = document.getElementById('pay');
console.log(pay.dataset.plan); // "pro"
console.log(pay.dataset.price); // "299"
</script> 8) Forms + validation basics (DOM side)
<form id="signup">
<input id="email" type="email" placeholder="Email" required />
<input id="pwd" type="password" placeholder="Password (min 6)" minlength="6" required />
<button>Sign Up</button>
</form>
<p id="status"></p>
<script>
const form = document.getElementById('signup');
const status = document.getElementById('status');
form.addEventListener('submit', (e) => {
e.preventDefault(); if (!form.checkValidity()) {
status.textContent = 'Please fix form errors.'; return; }
const email = document.getElementById('email').value;
status.textContent =Welcome, ${email}!; });
</script>
✅ Uses built-in HTML validation + DOM for feedback.
9) When should your JS run? (DOMContentLoaded, defer)
Option A: Put <script> at the end of <body>
HTML loads first → then script runs (elements exist).
Option B: Use defer in the head
<script src="app.js" defer></script> defer waits until HTML is parsed, then runs script.
Option C: Listen for the DOM to be ready
document.addEventListener('DOMContentLoaded', () => {
// safe to query and manipulate the DOM here }); 10) Mini build (step-by-step): Add items to a list + remove items
(Just a teaching demo; not a “challenge”)
<form id="todoForm">
<input id="todoInput" placeholder="New task..." />
<button>Add</button>
</form>
<ul id="todoList"></ul>
<script>
const form = document.getElementById('todoForm');
const input = document.getElementById('todoInput');
const list = document.getElementById('todoList');
form.addEventListener('submit', (e) => {
e.preventDefault();
const text = input.value.trim();
if (!text) return; // 1) create
const li = document.createElement('li');
li.textContent = text + ' ';
// remove button
const removeBtn = document.createElement('button');
removeBtn.textContent = '✖'; removeBtn.setAttribute('aria-label', 'Remove item');
li.append(removeBtn);
// 2) insert
list.appendChild(li);
// 3) clear input
input.value = ''; });
// Event delegation to remove items
list.addEventListener('click', (e) => {
if (e.target.tagName === 'BUTTON') {
e.target.parentElement.remove(); } });
</script> What you practiced here:
➤submit + preventDefault()
➤createElement / appendChild / append
➤event.target and delegation on the <ul>
11) Good habits & small gotchas
✅Prefer addEventListener over inline events.
✅Use textContent for text; innerHTML only when you must render HTML (never with untrusted input).
✅Prefer classes (classList) over inline styles.
✅Use defer or run code after DOMContentLoaded.
✅When attaching many handlers to many children, prefer event delegation on their parent.
✅Keep HTML semantic & accessible (use <button> for clickables, connect <label> with for to inputs, etc.).
🧠 Today you learned
✅The right way to handle events with addEventListener (and how to remove them).
✅The event object and how to use event.target.
✅The difference between input / change / submit / keyboard & mouse events.
✅Creating, inserting, cloning, and removing elements.
✅classList, attributes vs properties, and custom data- attributes.
✅How to organize scripts so the DOM exists when your code runs.
🔥🔥You just unlocked the power to build real interactive pages. 🚀
Assignment :
➤Add/Change html
https://youtu.be/WCRi7y6aNrQ?si=JkZyU_xqa5BzUksy
➤mouse events
https://youtu.be/g_vXSKbfUiQ?si=JiJzcKuj6O7pWNRP
➤key events
https://youtu.be/q32skvBgxo4?si=lc80uMObuZ-HUpTl
➤Hide/show
https://youtu.be/MkvHPOT4RS8?si=Zxre1aDV9tMPyzwr
➤Add/Change html
https://youtu.be/WCRi7y6aNrQ?si=JkZyU_xqa5BzUksy
➤mouse events
https://youtu.be/g_vXSKbfUiQ?si=JiJzcKuj6O7pWNRP
➤key events
https://youtu.be/q32skvBgxo4?si=lc80uMObuZ-HUpTl
➤Hide/show
https://youtu.be/MkvHPOT4RS8?si=Zxre1aDV9tMPyzwr
YouTube
How to ADD/CHANGE HTML using JavaScript 🛠️
#JavaScript #html #tutorial
00:00:00 setup
00:01:10 h1 element
00:09:32 list items
// STEP 1 CREATE THE ELEMENT
const newH1 = document.createElement("h1");
// STEP 2 ADD ATTRIBUTES/PROPERTIES
newH1.textContent = "I like pizza!";
newH1.id = "myH1";
newH1.style.color…
00:00:00 setup
00:01:10 h1 element
00:09:32 list items
// STEP 1 CREATE THE ELEMENT
const newH1 = document.createElement("h1");
// STEP 2 ADD ATTRIBUTES/PROPERTIES
newH1.textContent = "I like pizza!";
newH1.id = "myH1";
newH1.style.color…
🌟 Week 4 Day 7 Challenges 🌟
Hello my dear campers 🙌,
You’ve done amazing learning DOM events, onclick, createElement, and appendChild.
Now it’s time to practice with fun challenges that will push your creativity.
Pick any 3 challenges from the list below 👇
1. Click Counters for Like & Dislike Buttons 👍👎
What to do:
➤Create two buttons: "Like" and "Dislike".
➤Each button should count how many times it’s clicked and display the number.
💡Hint:
➥Use let likeCount = 0 and let dislikeCount = 0.
➥Update the text using textContent when a button is clicked.
2. Dynamic Color Changer 🎨
What to do:
➤Make a button that changes the background color of the page every time it’s clicked.
💡Hint:
➥Store a list of colors in an array like ["red", "blue", "green"].
➥On click, randomly pick a color and apply it with document.body.style.backgroundColor.
3. Task List Maker 📝
What to do:
➤Let the user type a task in an input box and add it as a list item when clicking “Add”.
💡Hint:
➥Use document.createElement("li") and appendChild to add new tasks into a <ul>.
➥Don’t forget to grab the input value with .value.
4. Image Switcher 🖼️
What to do:
➤Display an image and a button. When the button is clicked, the image changes.
💡Hint:
➥Use an array of image URLs.
➥Swap the src attribute of the <img> when the button is clicked.
5. Emoji Rain 🌸🍕😂
What to do:
➤Have a button that, when clicked, drops a new emoji onto the page.
💡Hint:
➥Use document.createElement("span").
➥Set its textContent to an emoji.
➥Append it to the body each time the button is clicked.
✨ Choose any 3 challenges, try them out, and have fun!
Don’t forget to
💥💥 share your solutions,
💥💥invite your friends,
and as always…
💥💥✌️✌️stay well, stay curious, and stay coding ✌️
Hello my dear campers 🙌,
You’ve done amazing learning DOM events, onclick, createElement, and appendChild.
Now it’s time to practice with fun challenges that will push your creativity.
Pick any 3 challenges from the list below 👇
1. Click Counters for Like & Dislike Buttons 👍👎
What to do:
➤Create two buttons: "Like" and "Dislike".
➤Each button should count how many times it’s clicked and display the number.
💡Hint:
➥Use let likeCount = 0 and let dislikeCount = 0.
➥Update the text using textContent when a button is clicked.
2. Dynamic Color Changer 🎨
What to do:
➤Make a button that changes the background color of the page every time it’s clicked.
💡Hint:
➥Store a list of colors in an array like ["red", "blue", "green"].
➥On click, randomly pick a color and apply it with document.body.style.backgroundColor.
3. Task List Maker 📝
What to do:
➤Let the user type a task in an input box and add it as a list item when clicking “Add”.
💡Hint:
➥Use document.createElement("li") and appendChild to add new tasks into a <ul>.
➥Don’t forget to grab the input value with .value.
4. Image Switcher 🖼️
What to do:
➤Display an image and a button. When the button is clicked, the image changes.
💡Hint:
➥Use an array of image URLs.
➥Swap the src attribute of the <img> when the button is clicked.
5. Emoji Rain 🌸🍕😂
What to do:
➤Have a button that, when clicked, drops a new emoji onto the page.
💡Hint:
➥Use document.createElement("span").
➥Set its textContent to an emoji.
➥Append it to the body each time the button is clicked.
✨ Choose any 3 challenges, try them out, and have fun!
Don’t forget to
💥💥 share your solutions,
💥💥invite your friends,
and as always…
💥💥✌️✌️stay well, stay curious, and stay coding ✌️
🌟 Week 4 Day 7 (Continued) — More DOM Practice with Examples
Hello Campers 👋,
Yesterday’s DOM session was a long ride, I know 😅. So today, instead of introducing new concepts, we’re going to strengthen what we learned through real-world, practical examples. Think of this as polishing the tools we got yesterday before moving forward.
1️⃣ ✅ Form Input Example — Username Display
Imagine you’re creating a website where someone types their username, and it appears immediately on the page.
🔎 Explanation:
➤input.addEventListener("input", ...) listens for typing.
➤Whatever you type is instantly shown inside the <span> → like live preview.
➤Real world use: think of Instagram showing your chosen username in real time.
2️⃣ 🎨 Button Example — Dark Mode Toggle
Most websites today have light mode / dark mode. Let’s simulate that.
🔎 Explanation:
➤We add/remove a class .dark using classList.toggle().
➤Button text also changes depending on the mode.
➤Real world use: exactly like YouTube or Twitter’s dark mode button.
3️⃣ 📝 Character Counter Example
You know when you type a tweet and it says “150 characters left”? Let’s build that.
🔎 Explanation:
➤maxlength="150" restricts typing beyond 150 characters.
➤Every keystroke updates the counter.
➤Real world use: Twitter, Facebook, or SMS apps do this.
4️⃣ 🎵 Image Hover Example — Album Preview
When you hover over an album cover, the picture changes (like previewing a music album or movie poster).
🔎 Explanation:
➤mouseover changes the image.
➤mouseout resets it back.
➤Real world use: online stores showing product preview images when you hover.
Hello Campers 👋,
Yesterday’s DOM session was a long ride, I know 😅. So today, instead of introducing new concepts, we’re going to strengthen what we learned through real-world, practical examples. Think of this as polishing the tools we got yesterday before moving forward.
1️⃣ ✅ Form Input Example — Username Display
Imagine you’re creating a website where someone types their username, and it appears immediately on the page.
<input type="text" id="usernameInput" placeholder="Enter your username" />
<p>Your username: <span id="displayUsername"></span></p>
<script>
const input = document.getElementById("usernameInput");
const display = document.getElementById("displayUsername");
input.addEventListener("input", function () {
display.textContent = input.value;
});
</script>
🔎 Explanation:
➤input.addEventListener("input", ...) listens for typing.
➤Whatever you type is instantly shown inside the <span> → like live preview.
➤Real world use: think of Instagram showing your chosen username in real time.
2️⃣ 🎨 Button Example — Dark Mode Toggle
Most websites today have light mode / dark mode. Let’s simulate that.
<button id="toggleBtn">Switch to Dark Mode</button>
<script>
const button = document.getElementById("toggleBtn");
button.addEventListener("click", function () {
document.body.classList.toggle("dark");
if (document.body.classList.contains("dark")) {
button.textContent = "Switch to Light Mode";
} else {
button.textContent = "Switch to Dark Mode";
}
});
</script>
<style>
body.dark {
background-color: black;
color: white;
}
</style>
🔎 Explanation:
➤We add/remove a class .dark using classList.toggle().
➤Button text also changes depending on the mode.
➤Real world use: exactly like YouTube or Twitter’s dark mode button.
3️⃣ 📝 Character Counter Example
You know when you type a tweet and it says “150 characters left”? Let’s build that.
<textarea id="tweetInput" rows="3" cols="30" maxlength="150"></textarea>
<p>Characters left: <span id="counter">150</span></p>
<script>
const textarea = document.getElementById("tweetInput");
const counter = document.getElementById("counter");
const max = 150;
textarea.addEventListener("input", function () {
let remaining = max - textarea.value.length;
counter.textContent = remaining;
});
</script>
🔎 Explanation:
➤maxlength="150" restricts typing beyond 150 characters.
➤Every keystroke updates the counter.
➤Real world use: Twitter, Facebook, or SMS apps do this.
4️⃣ 🎵 Image Hover Example — Album Preview
When you hover over an album cover, the picture changes (like previewing a music album or movie poster).
<img id="album" src="cover1.jpg" width="200">
<script>
const album = document.getElementById("album");
album.addEventListener("mouseover", function () {
album.src = "cover2.jpg";
});
album.addEventListener("mouseout", function () {
album.src = "cover1.jpg";
});
</script>
🔎 Explanation:
➤mouseover changes the image.
➤mouseout resets it back.
➤Real world use: online stores showing product preview images when you hover.
5️⃣ 🔍 Live Search Filter (Search While Typing)
Think about when you search for a contact or product and the list filters as you type.
🔎 Explanation:
➤Every time you type, the list is scanned.
➤Only names that include the typed letters stay visible.
➤Real world: search boxes in contacts apps, e-commerce, or file managers.
6️⃣ 📑 Tab Navigation (Switch Sections Without Reloading)
Websites often have tabs (e.g., Profile | Settings | Notifications).
🔎 Explanation:
➤All tabs are hidden at first.
➤Clicking a button reveals the right one.
➤Real world: Gmail or Facebook using tabs inside profile/settings sections.
7️⃣ 📂 Accordion (Open/Close Sections Like FAQs)
You’ve seen websites where FAQs expand when clicked.
🔎 Explanation:
➤Each button toggles the next section (nextElementSibling).
➤FAQ answers expand/collapse when clicked.
➤Real world: FAQ pages, product descriptions, app menus.
✅ That makes 7 practical DOM examples now, all taken from real websites you use daily.
👉 Tomorrow, we’ll move forward with new concepts. For today, make sure you retype these examples, play with them, and even modify them to fit your own creative ideas.
Stay curious, stay coding and Stay well 🥰✌️
Think about when you search for a contact or product and the list filters as you type.
<input type="text" id="searchInput" placeholder="Search names..." />
<ul id="namesList">
<li>Alem</li>
<li>Berihu</li>
<li>Chaltu</li>
<li>Dawit</li>
<li>Megersa</li>
</ul>
<script>
const input = document.getElementById("searchInput");
const list = document.getElementById("namesList").getElementsByTagName("li");
input.addEventListener("input", function () {
const filter = input.value.toLowerCase();
for (let i = 0; i < list.length; i++) {
let name = list[i].textContent.toLowerCase();
if (name.includes(filter)) {
list[i].style.display = ""; }
else { list[i].style.display = "none"; } }
});
</script> 🔎 Explanation:
➤Every time you type, the list is scanned.
➤Only names that include the typed letters stay visible.
➤Real world: search boxes in contacts apps, e-commerce, or file managers.
6️⃣ 📑 Tab Navigation (Switch Sections Without Reloading)
Websites often have tabs (e.g., Profile | Settings | Notifications).
<button onclick="showTab('profile')">Profile</button>
<button onclick="showTab('settings')">Settings</button>
<div id="profile" class="tab">Welcome to your profile!</div>
<div id="settings" class="tab" style="display:none;">Here are your settings.</div>
<script>
function showTab(tabId) {
const tabs = document.getElementsByClassName("tab");
for (let i = 0; i < tabs.length; i++) {
tabs[i].style.display = "none"; }
document.getElementById(tabId).style.display = "block"; }
</script> 🔎 Explanation:
➤All tabs are hidden at first.
➤Clicking a button reveals the right one.
➤Real world: Gmail or Facebook using tabs inside profile/settings sections.
7️⃣ 📂 Accordion (Open/Close Sections Like FAQs)
You’ve seen websites where FAQs expand when clicked.
<button class="accordion">What is JavaScript?</button>
<div class="panel">JavaScript is a programming language for the web.</div>
<button class="accordion">What is DOM?</button>
<div class="panel">DOM lets JavaScript interact with web pages.</div>
<script>
const acc = document.getElementsByClassName("accordion");
for (let i = 0; i < acc.length; i++) {
acc[i].addEventListener("click", function () {
const panel = this.nextElementSibling;
panel.style.display = panel.style.display === "block" ? "none" : "block"; });
}
</script>
<style>
.panel {
display: none;
padding: 5px;
background: #f1f1f1;
margin-bottom: 5px; }
</style> 🔎 Explanation:
➤Each button toggles the next section (nextElementSibling).
➤FAQ answers expand/collapse when clicked.
➤Real world: FAQ pages, product descriptions, app menus.
✅ That makes 7 practical DOM examples now, all taken from real websites you use daily.
👉 Tomorrow, we’ll move forward with new concepts. For today, make sure you retype these examples, play with them, and even modify them to fit your own creative ideas.
Stay curious, stay coding and Stay well 🥰✌️
🌞 Week 4 Day 8 — Forms & Validation in JavaScript
👋 Hello Campers!
I hope you’re doing great. We’ve gone through variables, functions, OOP, DOM, and events… and now it’s time to get into something very real-world: Forms & Validation.
Everywhere you go online — Facebook login, Google signup, online shopping checkout — you’re filling out forms. Without forms, websites are just pretty pages with no way to interact with users.
Today, we’ll dive deep into:
➤What forms are and how to grab their data with JavaScript.
➤Validating input (checking if it’s empty, long enough, or matches a rule).
➤Giving feedback to the user (error messages, colors, etc).
Let’s go step by step.
📝 1. Forms in HTML
A simple form looks like this:
👉 Notice:
➥<form> wraps everything.
➥Inputs (text, password, email, etc.) are where users type.
➥A button with type="submit" tries to send the form.
🎯 2. Accessing Form Data with JS
We need JavaScript to “catch” the values typed.
✨ Explanation:
➥event.preventDefault() is super important! By default, forms reload the page when submitted. This stops that.
➥.value gets whatever the user typed.
🚦 3. Basic Validation
Validation means checking: Is the input good enough?
Example: Require a username and a password of at least 6 characters.
💡 Tips:
➥.trim() removes spaces at start/end.
➥We use simple if statements to validate.
✨ 4. Real-World Example — Email Validation
Almost every form has an email field.
🎨 5. Better User Feedback
Instead of only alert(), we can show errors below inputs:
👉 Now errors appear directly below the inputs instead of annoying popups.
👋 Hello Campers!
I hope you’re doing great. We’ve gone through variables, functions, OOP, DOM, and events… and now it’s time to get into something very real-world: Forms & Validation.
Everywhere you go online — Facebook login, Google signup, online shopping checkout — you’re filling out forms. Without forms, websites are just pretty pages with no way to interact with users.
Today, we’ll dive deep into:
➤What forms are and how to grab their data with JavaScript.
➤Validating input (checking if it’s empty, long enough, or matches a rule).
➤Giving feedback to the user (error messages, colors, etc).
Let’s go step by step.
📝 1. Forms in HTML
A simple form looks like this:
<form id="signupForm">
<label>Username:</label>
<input type="text" id="username" /> <br><br>
<label>Password:</label>
<input type="password" id="password" /> <br><br>
<button type="submit">Sign Up</button>
</form> 👉 Notice:
➥<form> wraps everything.
➥Inputs (text, password, email, etc.) are where users type.
➥A button with type="submit" tries to send the form.
🎯 2. Accessing Form Data with JS
We need JavaScript to “catch” the values typed.
const form = document.getElementById("signupForm");
form.addEventListener("submit", function(event) {
event.preventDefault(); // stops the form from reloading the page
const username = document.getElementById("username").value;
const password = document.getElementById("password").value;
console.log("Username:", username);
console.log("Password:", password); });✨ Explanation:
➥event.preventDefault() is super important! By default, forms reload the page when submitted. This stops that.
➥.value gets whatever the user typed.
🚦 3. Basic Validation
Validation means checking: Is the input good enough?
Example: Require a username and a password of at least 6 characters.
form.addEventListener("submit", function(event) {
event.preventDefault();
const username = document.getElementById("username").value.trim();
const password = document.getElementById("password").value;
if (username === "") {
alert("Username cannot be empty!"); return; }
if (password.length < 6) {
alert("Password must be at least 6 characters long!"); return; }
alert("Form submitted successfully 🎉"); }); 💡 Tips:
➥.trim() removes spaces at start/end.
➥We use simple if statements to validate.
✨ 4. Real-World Example — Email Validation
Almost every form has an email field.
<form id="emailForm">
<input type="email" id="email" placeholder="Enter your email">
<button type="submit">Subscribe</button>
</form> const emailForm = document.getElementById("emailForm"); emailForm.addEventListener("submit", function(event) {
event.preventDefault();
const email = document.getElementById("email").value;
if (!email.includes("@") || !email.includes(".")) {
alert("Please enter a valid email!");
return; }
alert("Subscribed successfully ✅"); }); 🎨 5. Better User Feedback
Instead of only alert(), we can show errors below inputs:
<form id="loginForm">
<input type="text" id="user" placeholder="Username">
<p id="userError" style="color:red"></p>
<input type="password" id="pass" placeholder="Password">
<p id="passError" style="color:red"></p>
<button type="submit">Login</button>
</form> const loginForm = document.getElementById("loginForm");
loginForm.addEventListener("submit", function(event) {
event.preventDefault();
const user = document.getElementById("user").value.trim();
const pass = document.getElementById("pass").value;
const userError = document.getElementById("userError");
const passError = document.getElementById("passError"); // Clear old errors
userError.textContent = "";
passError.textContent = "";
if (user === "") {
userError.textContent = "Username required!"; return; }
if (pass.length < 6) {
passError.textContent = "Password too short!"; return; }
alert("Logged in 🎉"); });👉 Now errors appear directly below the inputs instead of annoying popups.
🏗️ 6. Real-World Analogy
Think of form validation like an airport security check ✈️:
➤If you bring a passport that’s expired → ❌ blocked (invalid input).
➤If your bag is too heavy → ❌ blocked (input doesn’t meet rules).
➤If everything checks out → ✅ you can board the plane (form submits).
➤Without validation, anyone could walk in with anything (hackers, bots, nonsense data).
🔑 7. Key Points to Remember
➤Forms collect user data.
➤.value gets the input.
➤Use .trim() to remove extra spaces.
➤Always use event.preventDefault() to stop page reloads.
➤Validate inputs before submitting (length, empty, special format).
➤Give user-friendly feedback (errors under inputs).
Think of form validation like an airport security check ✈️:
➤If you bring a passport that’s expired → ❌ blocked (invalid input).
➤If your bag is too heavy → ❌ blocked (input doesn’t meet rules).
➤If everything checks out → ✅ you can board the plane (form submits).
➤Without validation, anyone could walk in with anything (hackers, bots, nonsense data).
🔑 7. Key Points to Remember
➤Forms collect user data.
➤.value gets the input.
➤Use .trim() to remove extra spaces.
➤Always use event.preventDefault() to stop page reloads.
➤Validate inputs before submitting (length, empty, special format).
➤Give user-friendly feedback (errors under inputs).
🌟 Week 4 Day 8 Challenge: Ultimate Signup Form
👋 Hey Campers, hope you’re doing great! Today’s challenge is a big one 🎉. You’re going to build a Signup Form with validations + styling so it looks and feels like a real app.
✅ What to Do
Build a form with these fields:
✅Username
➤Cannot be empty.
➤At least 3 characters long.
➤No spaces allowed.
✅Email
➤Must have "@" and ".".
➤Show error if invalid.
✅Password & Confirm Password
➤Password must be at least 6 characters.
➤Confirm password must match.
✅Age
➤Must be 18 or older.
✅Phone Number
➤Must be exactly 10 digits.
✅Message / Bio
➤Optional, but if filled → at least 10 characters.
👉 Show error messages under each field.
👉 If everything is valid → display a big “Signup Successful!”.
🎨 Don’t Forget CSS!
Make it look nice:
➤Add some colors (green for success, red for errors).
➤Use margins and padding to space out inputs.
➤Add a hover effect to the submit button.
➤Maybe even round the corners with border-radius.
💡 Hints
➤Use .value.trim() to ignore empty spaces.
➤Use includes("@") and includes(".") for email checks.
➤Compare passwords with ===.
➤Use Number(age) for numeric checks.
➤Add/remove CSS classes like "error" or "success" to style feedback.
📢 Campers:
“This one is like building a real signup page 🌍. Make it functional and stylish. Share your creations, invite others to join the journey, and as always — stay well, stay curious, and stay coding ✌️.
👋 Hey Campers, hope you’re doing great! Today’s challenge is a big one 🎉. You’re going to build a Signup Form with validations + styling so it looks and feels like a real app.
✅ What to Do
Build a form with these fields:
✅Username
➤Cannot be empty.
➤At least 3 characters long.
➤No spaces allowed.
➤Must have "@" and ".".
➤Show error if invalid.
✅Password & Confirm Password
➤Password must be at least 6 characters.
➤Confirm password must match.
✅Age
➤Must be 18 or older.
✅Phone Number
➤Must be exactly 10 digits.
✅Message / Bio
➤Optional, but if filled → at least 10 characters.
👉 Show error messages under each field.
👉 If everything is valid → display a big “Signup Successful!”.
🎨 Don’t Forget CSS!
Make it look nice:
➤Add some colors (green for success, red for errors).
➤Use margins and padding to space out inputs.
➤Add a hover effect to the submit button.
➤Maybe even round the corners with border-radius.
💡 Hints
➤Use .value.trim() to ignore empty spaces.
➤Use includes("@") and includes(".") for email checks.
➤Compare passwords with ===.
➤Use Number(age) for numeric checks.
➤Add/remove CSS classes like "error" or "success" to style feedback.
📢 Campers:
“This one is like building a real signup page 🌍. Make it functional and stylish. Share your creations, invite others to join the journey, and as always — stay well, stay curious, and stay coding ✌️.
Want to study C++ or Python? My friend’s channel on YouTube uses great examples to make things easy to understand—take a look and subscribe.
https://youtube.com/@twohmschool?si=FuOAaJnKzW_WXtvZ
https://youtube.com/@twohmschool?si=FuOAaJnKzW_WXtvZ
YouTube
Two HM School
Hello 👋, everyone this is 2HM School, here we will post many educational videos , Please, subscribe, share and like our video totaly free and the only way to help us.THANK YOU ALL FOR SUPPORTING US!!!
🌟 Week 4 Day 9 — DOM Traverse, Sort & Shuffle, Date, Currency, Console Time, Destructuring
Hello Campers 👋,
First, big apology for the 3-day silence 🙏. Sometimes life gets busy. Teaching is about consistency, and I’ll keep showing up with you. Today we’ll break these topics into tiny bites with real-world meaning.
1️⃣ DOM Traversal (Walking around your HTML family tree)
Think of your HTML as a family tree:
➤Parent = the container
➤Children = elements inside it
➤Siblings = brothers/sisters (elements at the same level)
Example HTML:
JS Traversal:
👉 This is how we move around the DOM when we need not just one element but relationships.
2️⃣ Sorting Arrays
Sorting means arranging data in order (alphabetical, numeric, etc.).
Example: sorting numbers
👉 Always pass a compare function when sorting numbers.
3️⃣ Destructuring (Unpacking values quickly)
This is like saying:
“Instead of carrying a whole bag, let me just pull out the items I need.”
Arrays:
Objects:
👉 We’ll now use this in shuffling to make swaps shorter.
4️⃣ Shuffle Arrays (Randomize order)
Imagine shuffling cards in a game. We can randomize an array using the Fisher-Yates method.
👉 Thanks to destructuring, swapping values looks neat: [a, b] = [b, a];
5️⃣ Dates (Working with real-world time)
The Date object lets us work with today’s time.
👉 Note: months start at 0.
6️⃣ Currency Formatting
When showing money, we need proper formatting.
Hello Campers 👋,
First, big apology for the 3-day silence 🙏. Sometimes life gets busy. Teaching is about consistency, and I’ll keep showing up with you. Today we’ll break these topics into tiny bites with real-world meaning.
1️⃣ DOM Traversal (Walking around your HTML family tree)
Think of your HTML as a family tree:
➤Parent = the container
➤Children = elements inside it
➤Siblings = brothers/sisters (elements at the same level)
Example HTML:
<div id="family">
<p>Child 1</p>
<p>Child 2</p>
<p>Child 3</p>
</div> JS Traversal:
const parent = document.getElementById("family"); // Children (all kids) console.log(parent.children); // HTMLCollection
// ➤First & Last Child
console.log(parent.firstElementChild.textContent); // "Child 1" console.log(parent.lastElementChild.textContent); // "Child 3"
// ➤Parent of Child 2
let child2 = parent.children[1]; console.log(child2.parentElement.id); // "family"
//➤ Siblings
console.log(child2.previousElementSibling.textContent); // "Child 1"
console.log(child2.nextElementSibling.textContent); // "Child 3" 👉 This is how we move around the DOM when we need not just one element but relationships.
2️⃣ Sorting Arrays
Sorting means arranging data in order (alphabetical, numeric, etc.).
Example: sorting numbers
let scores = [40, 100, 1, 5, 25, 10];
// Wrong (default = alphabetical!) console.log(scores.sort()); // [1, 10, 100, 25, 40, 5]
// Correct numeric sort
scores.sort((a, b) => a - b);
console.log(scores); // [1, 5, 10, 25, 40, 100]
// Descending
scores.sort((a, b) => b - a);
console.log(scores); // [100, 40, 25, 10, 5, 1] 👉 Always pass a compare function when sorting numbers.
3️⃣ Destructuring (Unpacking values quickly)
This is like saying:
“Instead of carrying a whole bag, let me just pull out the items I need.”
Arrays:
let colors = ["red", "green", "blue"];
// Without destructuring:
let first = colors[0];
let second = colors[1];
// With destructuring:
let [c1, c2, c3] = colors;
console.log(c1); // red
console.log(c2); // green
console.log(c3); // blue Objects:
let student = { name: "Amina", age: 20, city: "Addis" };
// Without destructuring:
let n = student.name;
let c = student.city;
// With destructuring:
let { name, city } = student;
console.log(name); // Amina
console.log(city); // Addis
👉 We’ll now use this in shuffling to make swaps shorter.
4️⃣ Shuffle Arrays (Randomize order)
Imagine shuffling cards in a game. We can randomize an array using the Fisher-Yates method.
let students = ["Aman", "Lily", "Sara", "Kebede", "Muna"];
for (let i = students.length - 1; i > 0; i--) {
let j = Math.floor(Math.random() * (i + 1));
// Swap students[i] with students[j]
[students[i], students[j]] = [students[j], students[i]]; // destructuring swap }
console.log(students); 👉 Thanks to destructuring, swapping values looks neat: [a, b] = [b, a];
5️⃣ Dates (Working with real-world time)
The Date object lets us work with today’s time.
let now = new Date();
console.log(now); // full date & time
console.log(now.getFullYear()); // year
console.log(now.getMonth()); // 0-11 (0 = January)
console.log(now.getDate()); // day of month
console.log(now.getDay()); // 0-6 (0 = Sunday)
console.log(now.getHours()); // hour
console.log(now.toDateString()); // "Tue Aug 26 2025"
console.log(now.toLocaleString()); // local format 👉 Note: months start at 0.
6️⃣ Currency Formatting
When showing money, we need proper formatting.
let price = 12345.678;
// USD
console.log( new Intl.NumberFormat("en-US", { style: "currency", currency: "USD" }).format(price) ); // $12,345.68
// Ethiopian Birr
console.log( new Intl.NumberFormat("am-ET", { style: "currency", currency: "ETB" }).format(price) ); // Br 12,345.68👉 Intl.NumberFormat automatically localizes numbers & symbols.
7️⃣ Measuring Code Speed with console.time
We can measure how long a block of code takes to run.
👉 Useful when comparing different ways of solving a problem.
🎯 Wrap Up
Today we learned:
✔ How to move around HTML elements (DOM traversal)
✔ Sorting & shuffling arrays (with destructuring explained first!)
✔ Dates and how to format them
✔ Currency formatting for real apps
✔ Measuring performance with console.time
✔ Cleaner code with destructuring
Each of these may look small, but together they give you real-world tools you’ll use in projects like calculators, dashboards, games, and even ecommerce apps.
7️⃣ Measuring Code Speed with console.time
We can measure how long a block of code takes to run.
console.time("loop test");
let sum = 0;
for (let i = 0; i < 1_000_000; i++) {
sum += i; }
console.timeEnd("loop test");
// e.g. loop test: 12ms 👉 Useful when comparing different ways of solving a problem.
🎯 Wrap Up
Today we learned:
✔ How to move around HTML elements (DOM traversal)
✔ Sorting & shuffling arrays (with destructuring explained first!)
✔ Dates and how to format them
✔ Currency formatting for real apps
✔ Measuring performance with console.time
✔ Cleaner code with destructuring
Each of these may look small, but together they give you real-world tools you’ll use in projects like calculators, dashboards, games, and even ecommerce apps.
Assignment :
➤Dom traverse
https://youtu.be/RKXIMnSwUcg?si=FUKj1D4b7pC7XpFq
➤currency
https://youtu.be/HOMu48bTzz8?si=rERc7uTzUX89twhi
➤console.time
https://youtu.be/9amAW_qXv84?si=SA02eHAMPjKnn0Xf
➤date objects
https://youtu.be/LwYwz67l1lA?si=BRjHz1NMzeaxuyvH
➤shuffle
https://youtu.be/FGAUekwri1Q?si=HOUJ2olxK-PiBQNO
➤sorting
https://youtu.be/CTHhlx25X-U?si=nW90hcx3kTpSKiuo
➤destructuring
https://youtu.be/UHZcJyVXtLo?si=zpy9s31wdychlRm7
➤Dom traverse
https://youtu.be/RKXIMnSwUcg?si=FUKj1D4b7pC7XpFq
➤currency
https://youtu.be/HOMu48bTzz8?si=rERc7uTzUX89twhi
➤console.time
https://youtu.be/9amAW_qXv84?si=SA02eHAMPjKnn0Xf
➤date objects
https://youtu.be/LwYwz67l1lA?si=BRjHz1NMzeaxuyvH
➤shuffle
https://youtu.be/FGAUekwri1Q?si=HOUJ2olxK-PiBQNO
➤sorting
https://youtu.be/CTHhlx25X-U?si=nW90hcx3kTpSKiuo
➤destructuring
https://youtu.be/UHZcJyVXtLo?si=zpy9s31wdychlRm7
YouTube
Learn DOM Navigation in 15 minutes! 🧭
#JavaScript #tutorial #course
00:00:00 introduction
00:01:25 .firstElementChild
00:04:33 .lastElementChild
00:07:02 .nextElementSibling
00:10:03 .previousElementSibling
00:11:48 .parentElement
00:12:55 .children
00:15:04 conclusion
// DOM Navigation = The…
00:00:00 introduction
00:01:25 .firstElementChild
00:04:33 .lastElementChild
00:07:02 .nextElementSibling
00:10:03 .previousElementSibling
00:11:48 .parentElement
00:12:55 .children
00:15:04 conclusion
// DOM Navigation = The…
🌟 Project 1: Calculator & Digital Clock
Hello Campers 👋
I know we still haven't finished JavaScript , but it's time to use what we have learned so far for two real mini-apps. Using google is allowed, but make sure you understand every line of code.
1) 🧮 Calculator (Basic → Plus)
✅ What to build
A clean on-page calculator with:
➤Display screen
➤Buttons: 0–9, + - × ÷, . (decimal), =, C (clear), ← (backspace)
🧩 Core features
➤Click buttons to show numbers/operators on the display
➤= evaluates the expression and shows the result
➤C clears everything, ← removes last character
➤Prevent invalid inputs (e.g., two operators in a row)
🛠️ Suggested structure
✅HTML
▶️<div class="calc"> with a <input id="display" readonly>
▶️A grid of <button>s for digits/operators
✅CSS (ideas)
▶️Use CSS Grid for the buttons
▶️:hover and :active styles for click feedback
▶️Bigger font for display, subtle shadow for the calculator body
✅JS (flow)
▶️Grab all buttons and the display (document.getElementById, querySelectorAll)
▶️On button click, update display.value
▶️On =, safely evaluate (don’t use raw eval in real apps; for now you can map ×→*, ÷→/ and evaluate using Function or a simple parser)
▶️On C, set display.value = ''
▶️On ←, remove last char:
▶️display.value = display.value.slice(0, -1)
↪️Edge cases: avoid .. twice, avoid ++, --, **, //, and starting with an operator (except minus if you want negative numbers)
💡 Hints
➥Keep allowed chars list: digits 0–9, ., + - * /
➥Replace visual operators before evaluation: ➥input.replaceAll('×','*').replaceAll('÷','/')
➥Disable multiple operators in a row by checking the last character before appending
➥Optional: add keyboard support with keydown events
2) ⏰ Digital Clock (Live Time + Options)
✅ What to build
A live clock that updates every second:
Hours:Minutes:Seconds
AM/PM (12-hour) and 24-hour toggle
Day and date display
🧩 Core features
➤Show current time (HH:MM:SS)
➤Update every 1000 ms with setInterval
Format leading zeros (e.g., 09:05:03)
➤Show day name and full date
🛠️ Suggested structure
HTML
<div class="clock">
<div id="time"></div>
<div id="date"></div>
<button id="toggleFormat">Switch 12/24h</button>
CSS (ideas)
➤Big monospace font for time
➤Subtle gradient background
➤Center with Flexbox, add soft glow text-shadow
JS (flow)
➤Keep a state: let is24 = false;
➤function updateClock() {
const now = new Date()
Get hours/minutes/seconds
➤If 12-hour: hour = hour % 12 || 12 and add AM/PM
➤Format with a helper: pad(n) => n.toString().padStart(2,'0')
➤Build date string (e.g., Sunday, 17 September 2025)
Put into #time and #date
}
➤setInterval(updateClock, 1000); updateClock();
On toggle button click, flip is24 and re-render
💡 Hints
Arrays help format names:
➥const days = ["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];
➥const months = ["Jan","Feb",...,"Dec"];
➥Use textContent to update DOM efficiently
➥Use a single interval; don’t create multiple intervals on each click
📣 Final Notes
✅Keep your code clean: separate HTML structure, CSS styling, and JS behavior
✅Test edge cases (empty display on =, multiple operators, midnight formats, etc.)
Share your finished projects in the group, invite your friends, and as always—
stay well, stay curious, and stay coding ✌️
Hello Campers 👋
I know we still haven't finished JavaScript , but it's time to use what we have learned so far for two real mini-apps. Using google is allowed, but make sure you understand every line of code.
1) 🧮 Calculator (Basic → Plus)
✅ What to build
A clean on-page calculator with:
➤Display screen
➤Buttons: 0–9, + - × ÷, . (decimal), =, C (clear), ← (backspace)
🧩 Core features
➤Click buttons to show numbers/operators on the display
➤= evaluates the expression and shows the result
➤C clears everything, ← removes last character
➤Prevent invalid inputs (e.g., two operators in a row)
🛠️ Suggested structure
✅HTML
▶️<div class="calc"> with a <input id="display" readonly>
▶️A grid of <button>s for digits/operators
✅CSS (ideas)
▶️Use CSS Grid for the buttons
▶️:hover and :active styles for click feedback
▶️Bigger font for display, subtle shadow for the calculator body
✅JS (flow)
▶️Grab all buttons and the display (document.getElementById, querySelectorAll)
▶️On button click, update display.value
▶️On =, safely evaluate (don’t use raw eval in real apps; for now you can map ×→*, ÷→/ and evaluate using Function or a simple parser)
▶️On C, set display.value = ''
▶️On ←, remove last char:
▶️display.value = display.value.slice(0, -1)
↪️Edge cases: avoid .. twice, avoid ++, --, **, //, and starting with an operator (except minus if you want negative numbers)
💡 Hints
➥Keep allowed chars list: digits 0–9, ., + - * /
➥Replace visual operators before evaluation: ➥input.replaceAll('×','*').replaceAll('÷','/')
➥Disable multiple operators in a row by checking the last character before appending
➥Optional: add keyboard support with keydown events
2) ⏰ Digital Clock (Live Time + Options)
✅ What to build
A live clock that updates every second:
Hours:Minutes:Seconds
AM/PM (12-hour) and 24-hour toggle
Day and date display
🧩 Core features
➤Show current time (HH:MM:SS)
➤Update every 1000 ms with setInterval
Format leading zeros (e.g., 09:05:03)
➤Show day name and full date
🛠️ Suggested structure
HTML
<div class="clock">
<div id="time"></div>
<div id="date"></div>
<button id="toggleFormat">Switch 12/24h</button>
CSS (ideas)
➤Big monospace font for time
➤Subtle gradient background
➤Center with Flexbox, add soft glow text-shadow
JS (flow)
➤Keep a state: let is24 = false;
➤function updateClock() {
const now = new Date()
Get hours/minutes/seconds
➤If 12-hour: hour = hour % 12 || 12 and add AM/PM
➤Format with a helper: pad(n) => n.toString().padStart(2,'0')
➤Build date string (e.g., Sunday, 17 September 2025)
Put into #time and #date
}
➤setInterval(updateClock, 1000); updateClock();
On toggle button click, flip is24 and re-render
💡 Hints
Arrays help format names:
➥const days = ["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];
➥const months = ["Jan","Feb",...,"Dec"];
➥Use textContent to update DOM efficiently
➥Use a single interval; don’t create multiple intervals on each click
📣 Final Notes
✅Keep your code clean: separate HTML structure, CSS styling, and JS behavior
✅Test edge cases (empty display on =, multiple operators, midnight formats, etc.)
Share your finished projects in the group, invite your friends, and as always—
stay well, stay curious, and stay coding ✌️
🎉1
🌞 Week 5 Day 1 — Introduction to Asynchronous JavaScript
👋 Hello Campers!
Welcome to Week 5 of our Fullstack Summer Camp! We’ve been doing an amazing job so far — from variables and functions, all the way to DOM and OOP. Today, we are stepping into one of the most important (and a bit tricky) parts of JavaScript: Asynchronous Programming.
Don’t worry — we’ll take it step by step, with simple words, good analogies, and examples.
🕐 1. First, What Does "Asynchronous" Mean?
Synchronous = things happen one after the other.
Example: You stand in line to buy injera 🥙. Each person must finish buying before the next can order.
Asynchronous = things can happen while waiting.
Example: You order coffee ☕ at a café. The waiter tells you to sit, and while the coffee is being prepared, you can check your phone, talk to a friend, or do homework. You don’t need to stand stuck until it’s ready.
👉 That’s what JavaScript does: it allows some tasks to happen in the background (like waiting for data, downloading files, or timers) while the rest of the code keeps running.
🧵 2. Why Do We Need Async in JavaScript?
JavaScript is single-threaded — it can only do one thing at a time. If we write blocking code (like waiting 5 seconds), the whole page will freeze 😳.
Imagine:
You open a website.
The website tries to download a 5MB image.
If JavaScript was synchronous only, the entire page would stop until the image finished downloading. No scrolling, no clicking, nothing.
Asynchronous programming fixes this → it lets JS say:
👉 “Okay, I’ll start downloading this, but meanwhile, let me keep running the rest of the code. I’ll come back when the download is ready.”
🌀 3. The Event Loop — JavaScript’s Coffee Shop ☕
Here’s the magic of how async works:
➤Call Stack → where JavaScript runs your main code (line by line).
➤Web APIs / Background tasks → where timers, fetch requests, etc., wait.
➤Callback Queue → when those tasks are finished, they move here.
➤Event Loop → a helper that checks: “Is the stack empty? If yes, I’ll take a task from the queue and run it.”
👉 Analogy:
Think of a coffee shop:
➤The cashier = Call Stack (takes orders).
➤The barista = Web API (prepares coffee in the back).
➤The pick-up counter = Callback Queue (finished coffees waiting).
➤The waiter = Event Loop (delivers coffee when the cashier is free).
So, JS can keep “taking orders” while some work happens in the background.
💻 4. Examples of Synchronous vs Asynchronous
Example 1: Synchronous
Output (always in order):
Everything waits for the previous step.
Example 2: Asynchronous with setTimeout
Output:
👉 Notice: “Talk with friend” runs before coffee is ready. That’s async!
🔧 5. Common Asynchronous Functions in JS
➤setTimeout() → run code after some delay.
➤setInterval() → run code repeatedly after a time gap.
➤fetch() → get data from a server (we’ll learn in detail later).
➤Event listeners → e.g., when user clicks, the function is called later.
All these don’t block the code — they run in the background and “come back” when ready.
🌍 6. Real-World Examples
➤When you type in Google search → results load without reloading the whole page (async API calls).
➤When you scroll Instagram → new posts load in the background.
➤When you press play on YouTube → video streams while comments load separately.
📝 Key Takeaways
➤JavaScript is single-threaded (one main line of execution).
➤To avoid blocking, it uses asynchronous programming.
➤Async tasks (timers, requests, events) go to the Web APIs → then return later via the Event Loop.
➤Async = smoother, faster, more user-friendly apps.
👋 Hello Campers!
Welcome to Week 5 of our Fullstack Summer Camp! We’ve been doing an amazing job so far — from variables and functions, all the way to DOM and OOP. Today, we are stepping into one of the most important (and a bit tricky) parts of JavaScript: Asynchronous Programming.
Don’t worry — we’ll take it step by step, with simple words, good analogies, and examples.
🕐 1. First, What Does "Asynchronous" Mean?
Synchronous = things happen one after the other.
Example: You stand in line to buy injera 🥙. Each person must finish buying before the next can order.
Asynchronous = things can happen while waiting.
Example: You order coffee ☕ at a café. The waiter tells you to sit, and while the coffee is being prepared, you can check your phone, talk to a friend, or do homework. You don’t need to stand stuck until it’s ready.
👉 That’s what JavaScript does: it allows some tasks to happen in the background (like waiting for data, downloading files, or timers) while the rest of the code keeps running.
🧵 2. Why Do We Need Async in JavaScript?
JavaScript is single-threaded — it can only do one thing at a time. If we write blocking code (like waiting 5 seconds), the whole page will freeze 😳.
Imagine:
You open a website.
The website tries to download a 5MB image.
If JavaScript was synchronous only, the entire page would stop until the image finished downloading. No scrolling, no clicking, nothing.
Asynchronous programming fixes this → it lets JS say:
👉 “Okay, I’ll start downloading this, but meanwhile, let me keep running the rest of the code. I’ll come back when the download is ready.”
🌀 3. The Event Loop — JavaScript’s Coffee Shop ☕
Here’s the magic of how async works:
➤Call Stack → where JavaScript runs your main code (line by line).
➤Web APIs / Background tasks → where timers, fetch requests, etc., wait.
➤Callback Queue → when those tasks are finished, they move here.
➤Event Loop → a helper that checks: “Is the stack empty? If yes, I’ll take a task from the queue and run it.”
👉 Analogy:
Think of a coffee shop:
➤The cashier = Call Stack (takes orders).
➤The barista = Web API (prepares coffee in the back).
➤The pick-up counter = Callback Queue (finished coffees waiting).
➤The waiter = Event Loop (delivers coffee when the cashier is free).
So, JS can keep “taking orders” while some work happens in the background.
💻 4. Examples of Synchronous vs Asynchronous
Example 1: Synchronous
console.log("1. Order injera");
console.log("2. Wait until injera is ready");
console.log("3. Eat injera"); Output (always in order):
1. Order injera
2. Wait until injera is ready
3. Eat injera Everything waits for the previous step.
Example 2: Asynchronous with setTimeout
console.log("1. Order coffee");
setTimeout(() => { console.log("2. Coffee is ready!"); }, 2000);
console.log("3. Talk with friend"); Output:
1. Order coffee
3. Talk with friend
2. Coffee is ready! 👉 Notice: “Talk with friend” runs before coffee is ready. That’s async!
🔧 5. Common Asynchronous Functions in JS
➤setTimeout() → run code after some delay.
➤setInterval() → run code repeatedly after a time gap.
➤fetch() → get data from a server (we’ll learn in detail later).
➤Event listeners → e.g., when user clicks, the function is called later.
All these don’t block the code — they run in the background and “come back” when ready.
🌍 6. Real-World Examples
➤When you type in Google search → results load without reloading the whole page (async API calls).
➤When you scroll Instagram → new posts load in the background.
➤When you press play on YouTube → video streams while comments load separately.
📝 Key Takeaways
➤JavaScript is single-threaded (one main line of execution).
➤To avoid blocking, it uses asynchronous programming.
➤Async tasks (timers, requests, events) go to the Web APIs → then return later via the Event Loop.
➤Async = smoother, faster, more user-friendly apps.