ar
Feedback

لا تقع ضحية للمخادعين! تيليمتريو يكتشف ويُميّز هذه القنوات 👉 إذا كنت تريد رؤية العلامة، اشترك

Full Stack Camp

Full Stack Camp

الذهاب إلى القناة على Telegram

Fullstack Camp | Learn. Build. Launch. Join us for a hands-on journey through HTML, CSS, JavaScript, React, Node.js, Express & MongoDB — all in one place. Use this bot to search for lessons. @FullstackCamp_assistant_bot DM: @Tarikey6

إظهار المزيد
لم يتم تحديد البلدالفئة غير محددة
239
المشتركون
-124 ساعات
-37 أيام
+130 أيام
أرشيف المشاركات
\n\n🔎 Explanation:\n➤Every time you type, the list is scanned.\n➤Only names that include the typed letters stay visible.\n➤Real world: search boxes in contacts apps, e-commerce, or file managers.\n\n6️⃣ 📑 Tab Navigation (Switch Sections Without Reloading)\n\nWebsites often have tabs (e.g., Profile | Settings | Notifications).\n\n\n\n
Welcome to your profile!
\n
Here are your settings.
\n \n\n🔎 Explanation:\n➤All tabs are hidden at first.\n➤Clicking a button reveals the right one.\n➤Real world: Gmail or Facebook using tabs inside profile/settings sections.\n\n7️⃣ 📂 Accordion (Open/Close Sections Like FAQs)\n\nYou’ve seen websites where FAQs expand when clicked.\n\n \n
JavaScript is a programming language for the web.
\n\n
DOM lets JavaScript interact with web pages.
\n\n \n \n\n🔎 Explanation:\n➤Each button toggles the next section (nextElementSibling).\n➤FAQ answers expand/collapse when clicked.\n➤Real world: FAQ pages, product descriptions, app menus.\n\n✅ That makes 7 practical DOM examples now, all taken from real websites you use daily.\n\n👉 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.\n\nStay curious, stay coding and Stay well 🥰✌️","datePublished":"2025-08-21T13:08:30Z","dateModified":"2025-08-21T13:08:30Z","author":{"@type":"Organization","name":"Full Stack Camp","url":"https://telemetr.io/ar/channels/2504967936-fullstackcampp","image":"https://img.telemetr.io/c/2JwAAE/5999218308148218133?ty=x"},"publisher":{"@type":"Organization","name":"Full Stack Camp","url":"https://telemetr.io/ar/channels/2504967936-fullstackcampp","image":"https://img.telemetr.io/c/2JwAAE/5999218308148218133?ty=x"},"commentCount":0,"interactionStatistic":[{"@type":"InteractionCounter","interactionType":"https://schema.org/ViewAction","userInteractionCount":106}]}},{"@type":"ListItem","position":12,"item":{"@type":"SocialMediaPosting","@id":"https://telemetr.io/ar/channels/2504967936-fullstackcampp/posts/167","url":"https://telemetr.io/ar/channels/2504967936-fullstackcampp/posts/167","mainEntityOfPage":"https://telemetr.io/ar/channels/2504967936-fullstackcampp/posts/167","headline":"🌟 Week 4 Day 7 (Continued) — More DOM Practice with Examples Hello Campers 👋, Yesterday’s DOM session was a l…","articleBody":"🌟 Week 4 Day 7 (Continued) — More DOM Practice with Examples\n\nHello Campers 👋,\nYesterday’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.\n\n1️⃣ ✅ Form Input Example — Username Display\n\nImagine you’re creating a website where someone types their username, and it appears immediately on the page.\n\n\n

Your username:

\n\n\n\n🔎 Explanation:\n➤input.addEventListener(\"input\", ...) listens for typing.\n➤Whatever you type is instantly shown inside the → like live preview.\n➤Real world use: think of Instagram showing your chosen username in real time.\n\n2️⃣ 🎨 Button Example — Dark Mode Toggle\n\nMost websites today have light mode / dark mode. Let’s simulate that.\n\n\n\n\n\n\n🔎 Explanation:\n➤We add/remove a class .dark using classList.toggle().\n➤Button text also changes depending on the mode.\n➤Real world use: exactly like YouTube or Twitter’s dark mode button.\n\n3️⃣ 📝 Character Counter Example\n\nYou know when you type a tweet and it says “150 characters left”? Let’s build that.\n\n\n

Characters left: 150

\n\n\n\n🔎 Explanation:\n➤maxlength=\"150\" restricts typing beyond 150 characters.\n➤Every keystroke updates the counter.\n➤Real world use: Twitter, Facebook, or SMS apps do this.\n\n4️⃣ 🎵 Image Hover Example — Album Preview\n\nWhen you hover over an album cover, the picture changes (like previewing a music album or movie poster).\n\n\n\n\n\n🔎 Explanation:\n➤mouseover changes the image.\n➤mouseout resets it back.\n➤Real world use: online stores showing product preview images when you hover.","datePublished":"2025-08-21T13:08:13Z","dateModified":"2025-08-21T13:08:13Z","author":{"@type":"Organization","name":"Full Stack Camp","url":"https://telemetr.io/ar/channels/2504967936-fullstackcampp","image":"https://img.telemetr.io/c/2JwAAE/5999218308148218133?ty=x"},"publisher":{"@type":"Organization","name":"Full Stack Camp","url":"https://telemetr.io/ar/channels/2504967936-fullstackcampp","image":"https://img.telemetr.io/c/2JwAAE/5999218308148218133?ty=x"},"commentCount":0,"interactionStatistic":[{"@type":"InteractionCounter","interactionType":"https://schema.org/ViewAction","userInteractionCount":119}]}},{"@type":"ListItem","position":13,"item":{"@type":"SocialMediaPosting","@id":"https://telemetr.io/ar/channels/2504967936-fullstackcampp/posts/166","url":"https://telemetr.io/ar/channels/2504967936-fullstackcampp/posts/166","mainEntityOfPage":"https://telemetr.io/ar/channels/2504967936-fullstackcampp/posts/166","headline":"Full Stack Camp","datePublished":"2025-08-20T07:29:46Z","dateModified":"2025-08-20T07:29:46Z","author":{"@type":"Organization","name":"Full Stack Camp","url":"https://telemetr.io/ar/channels/2504967936-fullstackcampp","image":"https://img.telemetr.io/c/2JwAAE/5999218308148218133?ty=x"},"publisher":{"@type":"Organization","name":"Full Stack Camp","url":"https://telemetr.io/ar/channels/2504967936-fullstackcampp","image":"https://img.telemetr.io/c/2JwAAE/5999218308148218133?ty=x"},"commentCount":0,"interactionStatistic":[{"@type":"InteractionCounter","interactionType":"https://schema.org/ViewAction","userInteractionCount":155}]}},{"@type":"ListItem","position":14,"item":{"@type":"SocialMediaPosting","@id":"https://telemetr.io/ar/channels/2504967936-fullstackcampp/posts/165","url":"https://telemetr.io/ar/channels/2504967936-fullstackcampp/posts/165","mainEntityOfPage":"https://telemetr.io/ar/channels/2504967936-fullstackcampp/posts/165","headline":"Full Stack Camp","datePublished":"2025-08-20T07:29:28Z","dateModified":"2025-08-20T07:29:28Z","author":{"@type":"Organization","name":"Full Stack Camp","url":"https://telemetr.io/ar/channels/2504967936-fullstackcampp","image":"https://img.telemetr.io/c/2JwAAE/5999218308148218133?ty=x"},"publisher":{"@type":"Organization","name":"Full Stack Camp","url":"https://telemetr.io/ar/channels/2504967936-fullstackcampp","image":"https://img.telemetr.io/c/2JwAAE/5999218308148218133?ty=x"},"commentCount":0,"interactionStatistic":[{"@type":"InteractionCounter","interactionType":"https://schema.org/ViewAction","userInteractionCount":157}]}},{"@type":"ListItem","position":15,"item":{"@type":"SocialMediaPosting","@id":"https://telemetr.io/ar/channels/2504967936-fullstackcampp/posts/164","url":"https://telemetr.io/ar/channels/2504967936-fullstackcampp/posts/164","mainEntityOfPage":"https://telemetr.io/ar/channels/2504967936-fullstackcampp/posts/164","headline":"Full Stack Camp","datePublished":"2025-08-20T07:29:01Z","dateModified":"2025-08-20T07:29:01Z","author":{"@type":"Organization","name":"Full Stack Camp","url":"https://telemetr.io/ar/channels/2504967936-fullstackcampp","image":"https://img.telemetr.io/c/2JwAAE/5999218308148218133?ty=x"},"publisher":{"@type":"Organization","name":"Full Stack Camp","url":"https://telemetr.io/ar/channels/2504967936-fullstackcampp","image":"https://img.telemetr.io/c/2JwAAE/5999218308148218133?ty=x"},"commentCount":0,"interactionStatistic":[{"@type":"InteractionCounter","interactionType":"https://schema.org/ViewAction","userInteractionCount":161}]}},{"@type":"ListItem","position":16,"item":{"@type":"SocialMediaPosting","@id":"https://telemetr.io/ar/channels/2504967936-fullstackcampp/posts/163","url":"https://telemetr.io/ar/channels/2504967936-fullstackcampp/posts/163","mainEntityOfPage":"https://telemetr.io/ar/channels/2504967936-fullstackcampp/posts/163","headline":"🌟 Week 4 Day 7 Challenges 🌟 Hello my dear campers 🙌, You’ve done amazing learning DOM events, onclick, create…","articleBody":"🌟 Week 4 Day 7 Challenges 🌟\n\nHello my dear campers 🙌,\nYou’ve done amazing learning DOM events, onclick, createElement, and appendChild.\nNow it’s time to practice with fun challenges that will push your creativity.\n\nPick any 3 challenges from the list below 👇\n\n1. Click Counters for Like & Dislike Buttons 👍👎\n\nWhat to do:\n➤Create two buttons: \"Like\" and \"Dislike\".\n➤Each button should count how many times it’s clicked and display the number.\n💡Hint:\n➥Use let likeCount = 0 and let dislikeCount = 0.\n➥Update the text using textContent when a button is clicked.\n\n2. Dynamic Color Changer 🎨\n\nWhat to do:\n➤Make a button that changes the background color of the page every time it’s clicked.\n💡Hint:\n➥Store a list of colors in an array like [\"red\", \"blue\", \"green\"].\n➥On click, randomly pick a color and apply it with document.body.style.backgroundColor.\n\n3. Task List Maker 📝\n\nWhat to do:\n➤Let the user type a task in an input box and add it as a list item when clicking “Add”.\n💡Hint:\n➥Use document.createElement(\"li\") and appendChild to add new tasks into a
    .\n➥Don’t forget to grab the input value with .value.\n\n4. Image Switcher 🖼️\n\nWhat to do:\n➤Display an image and a button. When the button is clicked, the image changes.\n💡Hint:\n➥Use an array of image URLs.\n➥Swap the src attribute of the when the button is clicked.\n\n5. Emoji Rain 🌸🍕😂\n\nWhat to do:\n➤Have a button that, when clicked, drops a new emoji onto the page.\n💡Hint:\n➥Use document.createElement(\"span\").\n➥Set its textContent to an emoji.\n➥Append it to the body each time the button is clicked.\n\n✨ Choose any 3 challenges, try them out, and have fun!\n\nDon’t forget to\n💥💥 share your solutions, \n💥💥invite your friends, \nand as always… \n\n💥💥✌️✌️stay well, stay curious, and stay coding ✌️","datePublished":"2025-08-19T18:50:09Z","dateModified":"2025-08-19T18:50:09Z","author":{"@type":"Organization","name":"Full Stack Camp","url":"https://telemetr.io/ar/channels/2504967936-fullstackcampp","image":"https://img.telemetr.io/c/2JwAAE/5999218308148218133?ty=x"},"publisher":{"@type":"Organization","name":"Full Stack Camp","url":"https://telemetr.io/ar/channels/2504967936-fullstackcampp","image":"https://img.telemetr.io/c/2JwAAE/5999218308148218133?ty=x"},"commentCount":0,"interactionStatistic":[{"@type":"InteractionCounter","interactionType":"https://schema.org/ViewAction","userInteractionCount":167},{"@type":"InteractionCounter","interactionType":"https://schema.org/ShareAction","userInteractionCount":1}]}},{"@type":"ListItem","position":17,"item":{"@type":"SocialMediaPosting","@id":"https://telemetr.io/ar/channels/2504967936-fullstackcampp/posts/162","url":"https://telemetr.io/ar/channels/2504967936-fullstackcampp/posts/162","mainEntityOfPage":"https://telemetr.io/ar/channels/2504967936-fullstackcampp/posts/162","headline":"Assignment : ➤Add/Change html https://youtu.be/WCRi7y6aNrQ?si=JkZyU_xqa5BzUksy ➤mouse events https://youtu.be…","articleBody":"Assignment :\n➤Add/Change html \nhttps://youtu.be/WCRi7y6aNrQ?si=JkZyU_xqa5BzUksy\n➤mouse events\nhttps://youtu.be/g_vXSKbfUiQ?si=JiJzcKuj6O7pWNRP \n➤key events \nhttps://youtu.be/q32skvBgxo4?si=lc80uMObuZ-HUpTl\n➤Hide/show\nhttps://youtu.be/MkvHPOT4RS8?si=Zxre1aDV9tMPyzwr","datePublished":"2025-08-19T18:49:44Z","dateModified":"2025-08-19T18:49:44Z","author":{"@type":"Organization","name":"Full Stack Camp","url":"https://telemetr.io/ar/channels/2504967936-fullstackcampp","image":"https://img.telemetr.io/c/2JwAAE/5999218308148218133?ty=x"},"publisher":{"@type":"Organization","name":"Full Stack Camp","url":"https://telemetr.io/ar/channels/2504967936-fullstackcampp","image":"https://img.telemetr.io/c/2JwAAE/5999218308148218133?ty=x"},"commentCount":0,"interactionStatistic":[{"@type":"InteractionCounter","interactionType":"https://schema.org/ViewAction","userInteractionCount":108}]}},{"@type":"ListItem","position":18,"item":{"@type":"SocialMediaPosting","@id":"https://telemetr.io/ar/channels/2504967936-fullstackcampp/posts/161","url":"https://telemetr.io/ar/channels/2504967936-fullstackcampp/posts/161","mainEntityOfPage":"https://telemetr.io/ar/channels/2504967936-fullstackcampp/posts/161","headline":"B) Properties (often nicer) const img = document.querySelector('img'); img.src = 'cat.jpg'; img.alt = 'A cute…","articleBody":"B) Properties (often nicer)\n\nconst img = document.querySelector('img');\nimg.src = 'cat.jpg';\nimg.alt = 'A cute cat'; \nC) Custom data: data-* + dataset\n\n\n \n\n8) Forms + validation basics (DOM side)\n\n
    \n \n\n \n
    \n

    \n \n\n✅ Uses built-in HTML validation + DOM for feedback.\n\n9) When should your JS run? (DOMContentLoaded, defer)\n\nOption A: Put \ndefer waits until HTML is parsed, then runs script.\n\nOption C: Listen for the DOM to be ready\n\ndocument.addEventListener('DOMContentLoaded', () => {\n   // safe to query and manipulate the DOM here }); \n\n10) Mini build (step-by-step): Add items to a list + remove items\n(Just a teaching demo; not a “challenge”)\n\n
    \n\n \n
    \n
      \n \n\nWhat you practiced here:\n➤submit + preventDefault()\n➤createElement / appendChild / append\n➤event.target and delegation on the
        \n\n11) Good habits & small gotchas\n✅Prefer addEventListener over inline events.\n✅Use textContent for text; innerHTML only when you must render HTML (never with untrusted input).\n✅Prefer classes (classList) over inline styles.\n✅Use defer or run code after DOMContentLoaded.\n✅When attaching many handlers to many children, prefer event delegation on their parent.\n✅Keep HTML semantic & accessible (use \n\nProperty on element (okay for quick demos):\n\nconst btn = document.getElementById('myBtn'); btn.onclick = function () { console.log('Clicked!'); }; \n❗ Limitation: Only one onclick can exist at a time; assigning a new one overwrites the old.\n\nB) The modern way (recommended): addEventListener\n\nconst btn = document.getElementById('myBtn');\nfunction handleClick() {\n      console.log('Clicked!'); }\n\nbtn.addEventListener('click', handleClick); \n\n✅ You can attach multiple listeners, remove them later, and choose options (like capture/once/passive).\n\nTo remove a listener, you need the same function reference:\n\nbtn.removeEventListener('click', handleClick); \n\n2) The event object (event / e)\nWhen an event happens, the browser gives you an event object with details about it.\n\ndocument.addEventListener('click', function (e) {\n     console.log('Type:', e.type); // \"click\" \n     console.log('Target:', e.target); // the element that was clicked\n      console.log('Coordinates:', e.clientX, e.clientY); }); \n3) Common, super-useful events\nA) click\n\n\n

        0

        \n \n\nB) input vs change (text fields, selects)\n\ninput fires on every keystroke (live updates).\nchange fires when the element loses focus or the selection finalizes.\n\n\n

        \n \n\nC) submit (forms) + preventing reload\nForms submit by default (page reload). Stop that with event.preventDefault().\n\n
        \n\n\n \n
        \n

        \n \n\nD) Keyboard events: keydown, keyup\n\n\n

        \n \n\nE) Mouse events: mouseover / mouseout / mousemove\n\n
        \n
        \n

        \n","datePublished":"2025-08-19T18:48:16Z","dateModified":"2025-08-19T18:48:16Z","author":{"@type":"Organization","name":"Full Stack Camp","url":"https://telemetr.io/ar/channels/2504967936-fullstackcampp","image":"https://img.telemetr.io/c/2JwAAE/5999218308148218133?ty=x"},"publisher":{"@type":"Organization","name":"Full Stack Camp","url":"https://telemetr.io/ar/channels/2504967936-fullstackcampp","image":"https://img.telemetr.io/c/2JwAAE/5999218308148218133?ty=x"},"commentCount":0,"interactionStatistic":[{"@type":"InteractionCounter","interactionType":"https://schema.org/ViewAction","userInteractionCount":92},{"@type":"InteractionCounter","interactionType":"https://schema.org/ShareAction","userInteractionCount":1}]}}]}
        challenges of week 4.zip1.17 MB
        29 أغسطس 2025, 06:46

        Where do you currently stand on this?
        Anonymous voting
        28 أغسطس 2025, 03:08

        🌟 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 ✌️
        26 أغسطس 2025, 11:20

        👉 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.
        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.
        26 أغسطس 2025, 11:19

        🌟 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:
        <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
        26 أغسطس 2025, 11:18

        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
        24 أغسطس 2025, 13:12

        🌟 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 ✌️.
        23 أغسطس 2025, 08:01

        🏗️ 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).
        23 أغسطس 2025, 08:01

        🌞 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:
        <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.
        23 أغسطس 2025, 08:01

        5️⃣ 🔍 Live Search Filter (Search While Typing) 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 🥰✌️
        21 أغسطس 2025, 09:08

        🌟 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.
        <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.
        21 أغسطس 2025, 09:08

        week4day5.js0.04 KB
        20 أغسطس 2025, 03:29

        week4day4.js0.04 KB
        20 أغسطس 2025, 03:29

        week4day3.js0.02 KB
        20 أغسطس 2025, 03:29

        🌟 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 ✌️
        19 أغسطس 2025, 14:50

        B) Properties (often nicer)
        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. 🚀
        19 أغسطس 2025, 14:49

        F) Focus events: focus / blur
        <input id="email" placeholder="Email" /> <p id="hint"></p> <script> const email = document.getElementById('email'); const hint = document.getElementById('hint'); email.addEventListener('focus', () => hint.textContent = 'Format: name@example.com'); email.addEventListener('blur', () => hint.textContent = ''); </script>
        4) Event Bubbling, Capturing & Delegation (beginner-friendly) Bubbling & Capturing (just enough to use) When you click a child element, the event travels: ➤Capturing: from document → down to the target. ➤Bubbling: from the target → back up to document (this is the default most people use). ➤addEventListener(type, handler, options): ➤{ capture: true } makes the handler run on the capturing phase. ➤{ once: true } runs the handler only once. ➤{ passive: true } tells the browser the handler won’t call preventDefault() (useful for scroll). Event Delegation (powerful & simple) Attach one listener to a parent and handle many children based on e.target.
        <ul id="menu"> <li data-action="home">Home</li> <li data-action="about">About</li> <li data-action="contact">Contact</li> </ul> <p id="out"></p> <script> const menu = document.getElementById('menu'); const out = document.getElementById('out'); menu.addEventListener('click', (e) => {     if (e.target.matches('li')) {     const action = e.target.dataset.action; // from data-action     out.textContent = You clicked: ${action}; } }); </script>
        ✅ Works even if you later add more <li>s—one listener handles all. 5) Creating & inserting elements (the dynamic DOM) A) createElement, set content/attrs, then insert
        <ul id="todos"></ul> <script> const todos = document.getElementById('todos'); const li = document.createElement('li'); li.textContent = 'Learn DOM'; li.setAttribute('data-priority', 'high'); todos.appendChild(li); // insert as last child </script>
        B) append, prepend, before, after, insertBefore
        <div id="wrap"> <p>First</p> </div> <script> const wrap = document.getElementById('wrap'); const p1 = document.createElement('p'); p1.textContent = 'Appended at end'; wrap.append(p1); const p2 = document.createElement('p'); p2.textContent = 'Prepended at start'; wrap.prepend(p2); const outsideTop = document.createElement('p'); outsideTop.textContent = 'Before the wrapper'; wrap.before(outsideTop); const outsideBottom = document.createElement('p'); outsideBottom.textContent = 'After the wrapper'; wrap.after(outsideBottom); </script>
        C) Removing elements: element.remove() or parent.removeChild(child)
        const item = document.querySelector('#todos li'); item.remove(); // easy way // or old-school: const parent = document.getElementById('todos'); const first = parent.firstElementChild; parent.removeChild(first);
        D) Cloning nodes: cloneNode
        const original = document.querySelector('#todos li'); const copy = original.cloneNode(true); // true = deep clone (children too) original.after(copy);
        E) innerHTML vs textContent (safety & speed) ➤textContent → sets text only (safe; shows <b> as text). ➤innerHTML → parses as HTML (powerful, but never put untrusted user input here—XSS risk).
        const box = document.getElementById('box'); box.textContent = '<b>hello</b>'; // shows literally <b>hello</b> box.innerHTML = '<b>hello</b>'; // renders bold hello
        6) Managing classes & styles cleanly A) classList
        const card = document.getElementById('card'); card.classList.add('active'); card.classList.remove('hidden'); card.classList.toggle('highlight'); // add if missing, remove if present const hasIt = card.classList.contains('active');
        B) Inline styles vs CSS classes Prefer toggling classes (cleaner). Inline styles are fine for quick demos:
        card.style.backgroundColor = 'lightyellow'; card.style.border = '1px solid #ccc';
        7) Attributes, properties, and dataset A) getAttribute / setAttribute
        const link = document.querySelector('a'); link.setAttribute('href', 'https://example.com'); console.log(link.getAttribute('href'));
        
        19 أغسطس 2025, 14:48

        🌞 Week 4 — Day 7: DOM Events & Dynamic Elements (Deep deep Dive!) Hey amazing campers 👋😄 You’ve met the DOM and learned how to select elements and change them. Today we’ll make pages come alive with events (clicks, typing, submitting, mouse moves…) and learn how to create, insert, and remove elements with JavaScript. This is the moment JS starts to feel magical. ✨ 0) Quick mental model: what’s an “event”? An event is something that happens in (or to) the page: a button is clicked, a user types in a field, a form is submitted, an image finishes loading, etc. We can listen for that event and then run code in response. That’s interactivity. 1) Two ways to listen for events A) The old way (inline or property) Inline in HTML (not recommended):
        <button onclick="alert('Clicked!')">Click me</button>
        Property on element (okay for quick demos):
        const btn = document.getElementById('myBtn'); btn.onclick = function () { console.log('Clicked!'); };
        ❗ Limitation: Only one onclick can exist at a time; assigning a new one overwrites the old. B) The modern way (recommended): addEventListener
        const btn = document.getElementById('myBtn'); function handleClick() {       console.log('Clicked!'); } btn.addEventListener('click', handleClick);
        ✅ You can attach multiple listeners, remove them later, and choose options (like capture/once/passive). To remove a listener, you need the same function reference:
        btn.removeEventListener('click', handleClick);
        2) The event object (event / e) When an event happens, the browser gives you an event object with details about it.
        document.addEventListener('click', function (e) {      console.log('Type:', e.type); // "click"      console.log('Target:', e.target); // the element that was clicked       console.log('Coordinates:', e.clientX, e.clientY); });
        3) Common, super-useful events A) click
        <button id="likeBtn">👍 Like</button> <p id="count">0</p> <script> const likeBtn = document.getElementById('likeBtn'); const out = document.getElementById('count'); let likes = 0; likeBtn.addEventListener('click', () => {       likes += 1;      out.textContent = likes; }); </script>
        B) input vs change (text fields, selects) input fires on every keystroke (live updates). change fires when the element loses focus or the selection finalizes.
        <input id="nameField" placeholder="Type your name..." /> <p id="preview"></p> <script> const nameField = document.getElementById('nameField'); const preview = document.getElementById('preview'); nameField.addEventListener('input', () => {     preview.textContent = Hello, ${nameField.value || 'stranger'}!; }); </script>
        C) submit (forms) + preventing reload Forms submit by default (page reload). Stop that with event.preventDefault().
        <form id="loginForm"> <input name="user" placeholder="Username" required /> <input name="pass" type="password" placeholder="Password" required /> <button>Log in</button> </form> <p id="msg"></p> <script> const form = document.getElementById('loginForm'); const msg = document.getElementById('msg'); form.addEventListener('submit', (e) => {      e.preventDefault(); // stop page reload const user = form.user.value; const pass = form.pass.value; msg.textContent = Trying to log in as: ${user} (password length: ${pass.length}); }); </script>
        D) Keyboard events: keydown, keyup
        <input id="command" placeholder="Type then press Enter" /> <p id="result"></p> <script> const command = document.getElementById('command'); const result = document.getElementById('result'); command.addEventListener('keydown', (e) => {    if (e.key === 'Enter') { result.textContent = You entered: ${command.value}; } }); </script>
        E) Mouse events: mouseover / mouseout / mousemove
        <div id="box" style="width:200px;height:120px;background:#eef;border:1px solid #99f;"> </div> <p id="coord"></p> <script> const box = document.getElementById('box'); const coord = document.getElementById('coord'); box.addEventListener('mousemove', (e) => { coord.textContent = x: ${e.offsetX}, y: ${e.offsetY}; }); </script>
        19 أغسطس 2025, 14:48