Frontend Machine Coding Interview | Star Rating Component | HTML | CSS | Javascript

แชร์
ฝัง
  • เผยแพร่เมื่อ 6 ก.พ. 2025

ความคิดเห็น • 14

  • @BlessedLife97
    @BlessedLife97 27 วันที่ผ่านมา +1

  • @Truthwithfactss
    @Truthwithfactss 10 หลายเดือนก่อน +3

    Nice and clear explanation...

    • @Vijay_Bhati
      @Vijay_Bhati  10 หลายเดือนก่อน +2

      I am glad you liked it 😊

  • @Vijay_Bhati
    @Vijay_Bhati  2 ปีที่แล้ว +3

    UI :- rating-component-normal.netlify.app/
    Code :- github.com/vj98/Frontend-Machine-Coding/tree/main/rating-component

    • @pets_ff_008
      @pets_ff_008 7 หลายเดือนก่อน +1

      Its very use full

  • @opinformation2233
    @opinformation2233 ปีที่แล้ว +2

    Its good bro keeping doing more

    • @Vijay_Bhati
      @Vijay_Bhati  ปีที่แล้ว +1

      I am happy you find the content useful 😊. For more such content Subscribe to the channel and Here is the playlist of Frontend Machine Coding Interview Problems th-cam.com/play/PLBygUld3s6x8sI_H8UYROVMIVcuxUre1e.html

  • @rishabhkansal5811
    @rishabhkansal5811 ปีที่แล้ว +1

    Its great!! 😊 Thanks so much.
    Please make more content on machine coding questions with HTML, CSS, JS

    • @Vijay_Bhati
      @Vijay_Bhati  ปีที่แล้ว +1

      Frontend Machine Coding Interview Problems th-cam.com/play/PLBygUld3s6x8sI_H8UYROVMIVcuxUre1e.html

  • @rayyanabdulwajid7681
    @rayyanabdulwajid7681 ปีที่แล้ว +1

    This is possible even without javascript, i saw a code on codepen. Thanks anyway for the knowledge

    • @Vijay_Bhati
      @Vijay_Bhati  ปีที่แล้ว +1

      Okay, but you must understand how it works behind the scenes in any form and with any method.

    • @rayyanabdulwajid7681
      @rayyanabdulwajid7681 ปีที่แล้ว +1

      @@Vijay_Bhati You're right

  • @ishanksainger2627
    @ishanksainger2627 ปีที่แล้ว +2

    Thanks for the code, I did some modifications.
    let starRating = document.querySelectorAll(".star");
    let ratingCount = document.getElementById("count");
    starRating.forEach((star, index) => {
    star.addEventListener("click", () => {
    if (star.classList.contains("active")) {
    for (let i = starRating.length-1; i > index; i--) {
    starRating[i].classList.remove("active");
    }
    } else {
    for (let i = 0; i < index + 1; i++) {
    starRating[i].classList.add("active");
    }
    }
    let activeStars = document.querySelectorAll(".star.active").length;
    ratingCount.innerHTML = `Rating Count : ${activeStars}`;
    });
    });
    starRating.forEach((star, index) => {
    star.addEventListener("mouseover", () => {
    for (let i = 0; i < index + 1; i++) {
    starRating[i].classList.add("hovered");
    }
    });
    });
    starRating.forEach((star, index) => {
    star.addEventListener("mouseout", () => {
    for (let i = 0; i < index + 1; i++) {
    starRating[i].classList.remove("hovered");
    }
    });
    });

  • @just_a_living_being
    @just_a_living_being ปีที่แล้ว +1

    Thank you for the video, this is my solution just modified your solution and added event delegation to avoid unnecessary click and mouseover events.
    const starContainer = document.getElementById('star-container')
    const stars = document.querySelectorAll('.star')
    const count = document.getElementById('count')
    let filled = 0
    starContainer.addEventListener('click', e => {
    if (e.target.matches('span')) {
    const rating = e.target.dataset.rating
    for (let j = 0; j < filled; j++) {
    stars[j].classList.remove('star-filled')
    }
    for (let i = 0; i < rating; i++) {
    stars[i].classList.add('star-filled')
    }
    filled = rating
    count.innerText = `Rating Count : ${filled}`
    }
    })
    starContainer.addEventListener('mouseover', e => {
    if (e.target.matches('span')) {
    const rating = e.target.dataset.rating
    for (let j = 0; j < filled; j++) {
    stars[j].classList.remove('star-filled')
    }
    for (let i = 0; i < rating; i++) {
    stars[i].classList.add('star-filled')
    }
    }
    })
    starContainer.addEventListener('mouseleave', e => {
    for (let j = 0; j < 5; j++) {
    stars[j].classList.remove('star-filled')
    }
    for (let i = 0; i < filled; i++) {
    stars[i].classList.add('star-filled')
    }
    })