๐Ÿง  Day 29 — Advanced DOM Projects

๐Ÿง  Day 29 — Advanced DOM Projects

Hey guys ,Welcome to Day 29 of the JavaScript Advanced Course! Today, we explore three advanced DOM projects that challenge your creativity and coding skills: a Color Picker, an Image Slider, and a Quiz App. These are popular interview tasks, and mastering them builds strong client-side development expertise.


๐Ÿ“Œ 1. Why Advanced DOM Projects Matter

DOM (Document Object Model) manipulation is the backbone of frontend development. Real-world applications require dynamic UI updates such as:

  • Live data updates
  • Dynamic forms and content
  • Interactive widgets
  • Animations
  • Complex event handling
  • Visual transitions and UI states

Today's projects help you:

  • Master event handling
  • Work with CSS dynamically
  • Handle timers and autoplay
  • Create reusable UI components
  • Design real-world mini-apps without frameworks

๐ŸŽจ Project 1 — Color Picker (Advanced Version)

A Color Picker is an excellent DOM project that interacts with input values, modifies CSS properties dynamically, and updates UI instantly. This upgraded version includes:

  • Live preview box
  • Hex + RGB conversion
  • Copy-to-clipboard button
  • Auto text color adjustment

๐Ÿ“„ HTML Structure

⚙ JavaScript Logic

const colorInput = document.getElementById("colorInput");
const preview = document.getElementById("preview");
const hexValue = document.getElementById("hexValue");
const rgbValue = document.getElementById("rgbValue");
const copyBtn = document.getElementById("copyBtn");

colorInput.addEventListener("input", () => {
  const color = colorInput.value;
  preview.style.background = color;
  hexValue.textContent = "Hex: " + color;

  const rgb = hexToRGB(color);
  rgbValue.textContent = "RGB: " + rgb;
});

function hexToRGB(h){
  let r = parseInt(h.substr(1,2),16);
  let g = parseInt(h.substr(3,2),16);
  let b = parseInt(h.substr(5,2),16);
  return `${r}, ${g}, ${b}`;
}

copyBtn.addEventListener("click", () => {
  navigator.clipboard.writeText(colorInput.value);
  alert("Copied: " + colorInput.value);
});

๐ŸŽจ Styling

Basic styling for the preview and buttons:

.previewBox {
  width:100%;
  height:120px;
  margin:15px 0;
  border-radius:8px;
  border:1px solid #ddd;
}

This project shows your ability to work with CSS, events, conversions, and UI responsiveness.


๐Ÿ–ผ Project 2 — Image Slider (Autoplay + Manual Controls)

An image slider is required in almost every website — portfolios, ecommerce, blogs, landing pages. This upgraded slider supports:

  • Next/Prev navigation
  • Autoplay
  • Pause on hover
  • Smooth transitions
  • Dot indicators

๐Ÿ“„ HTML Structure

⚙ JavaScript Logic

Slider images array:

const images = ["img1.jpg", "img2.jpg", "img3.jpg"];
let index = 0;

const slide = document.getElementById("slide");
const next = document.getElementById("next");
const prev = document.getElementById("prev");
const dots = document.getElementById("dots");

Render dots:

images.forEach((_,i) => {
  const d = document.createElement("span");
  d.className = "dot";
  d.addEventListener("click", () => show(i));
  dots.appendChild(d);
});

Main show function:

function show(i){
  index = (i + images.length) % images.length;
  slide.src = images[index];

  [...dots.children].forEach((d,j) => {
    d.style.background = j === index ? "#43a047" : "#bbb";
  });
}
show(0);

Navigation:

next.onclick = () => show(index+1);
prev.onclick = () => show(index-1);

Autoplay (with pause on hover):

let auto = setInterval(() => show(index+1), 2000);

slide.addEventListener("mouseover", () => clearInterval(auto));
slide.addEventListener("mouseout", () => auto=setInterval(() => show(index+1), 2000));

This is a full dynamic UI component with DOM manipulation, timers, events, & animations.


❓ Project 3 — Quiz App (Timer + Scoring + Next Button)

The Quiz App is one of the best beginner-to-advanced DOM projects. Today’s version includes:

  • Multiple questions
  • Next button
  • Score tracking
  • Timer for each question
  • Highlight right/wrong answers

๐Ÿ“„ HTML Structure

Time left: 10s

⚙ JavaScript Logic

Questions Array:

const questions = [
  {
    q:"JavaScript was created by?",
    opt:["Brendan Eich","Mark Zuckerberg","Elon Musk","Steve Jobs"],
    ans:0
  },
  {
    q:"Which method adds an element to the end of an array?",
    opt:["push()","pop()","shift()","unshift()"],
    ans:0
  }
];

Track quiz state:

let current = 0;
let score = 0;
let time = 10;
let timer;

Load question:

function load(){
  const q = questions[current];
  document.getElementById("q").textContent = q.q;

  const options = document.getElementById("options");
  options.innerHTML = "";

  q.opt.forEach((o,i)=>{
    const btn = document.createElement("button");
    btn.textContent = o;
    btn.onclick = () => select(i);
    options.appendChild(btn);
  });

  startTimer();
}
load();

Timer:

function startTimer(){
  time = 10;
  document.getElementById("timer").textContent = time;

  clearInterval(timer);
  timer = setInterval(() => {
    time--;
    document.getElementById("timer").textContent = time;
    if (time === 0) {
      nextQuestion();
    }
  },1000);
}

Check answer:

function select(i){
  if (i === questions[current].ans){
    score++;
  }
  nextQuestion();
}

Next question:

function nextQuestion(){
  current++;
  if (current === questions.length){
    endQuiz();
  } else {
    load();
  }
}

End screen:

function endQuiz(){
  document.querySelector(".quiz").innerHTML =
    `

Score: ${score} / ${questions.length}

`; clearInterval(timer); }

⭐ Add-on Features

  • Progress bar
  • Leaderboard stored in LocalStorage
  • Show correct answers after every question
  • Category selection
  • Random questions
  • Firebase backend

Adding even one of these makes your Quiz App look professional.


๐Ÿงช Live Demo (Embed)


๐Ÿ“ Practice Tasks

  1. Add voice assistance (read questions aloud).
  2. Add animations when selecting answers.
  3. Make image slider responsive.
  4. Add color palettes to the color picker.
  5. Create a theme switcher (dark mode).

๐ŸŽฏ Summary

Today’s lesson challenged you with **three real-world DOM projects** — Color Picker, Slider, and Quiz App. By working on these, you learn event handling, UI state management, timers, conversions, dynamic rendering, and component-based logic. These apps strengthen your frontend skills and look excellent in your portfolio.

Comments