Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found

Submitted

SASS for flexible CSS, Media queries for responsive Design

#sass/scss
Dytomaโ€ข 570

@Dytoma

Desktop design screenshot for the Interactive rating component coding challenge

This is a solution for...

  • HTML
  • CSS
  • JS
1newbie
View challenge

Design comparison


SolutionDesign

Solution retrospective


This a solution to the frontend challenge on interactive rating component. I used Javascript on this challenge but I don't know if this is best practice so if you have time check out the repository and I would appreciate having any feedback, tip or remarks. Thanks.

Community feedback

@VCarames

Posted

Hey there! ๐Ÿ‘‹ Here are some suggestions to help improve your code:

  • not only improve your HTML code but to identify the main content of you page, you will want to wrap your entire component inside the main element.

More Info:๐Ÿ“š

MDN Main Element

  • The โ€œicons/illustrationsโ€ in this component serve no other purpose than to be decorative; They add no value. There alt tag should be left blank and have an aria-hidden=โ€œtrueโ€ to hide them from assistive technology.

More Info:๐Ÿ“š

https://www.w3.org/WAI/tutorials/images/

  • The proper way to build the "rating buttons" in this challenge is to create a form and inside of it, there should be fiveinput radios and each input should have a label attached to it to make the buttons accessible. Finally wrap all the inputs and labels inside a fieldset to prevent users from making more than one selection.

More Info:๐Ÿ“š

MDN <input type="radio">

MDN <fieldset>: The Field Set element

  • The attribution should be wrapped in a footer element.

If you have any questions or need further clarification, feel free to reach out to me.

Happy Coding!๐ŸŽ„๐ŸŽ

Marked as helpful

1

Dytomaโ€ข 570

@Dytoma

Posted

@vcarames Thank you a lot for your tips. I will apply that to my next project.

1
Elaineโ€ข 11,420

@elaineleung

Posted

Hi Dytoma, this looks like a great start, and I think your code works fine. I do suggest giving your classes and variables more meaning names, where instead of

const rating = document.querySelectorAll(".nbr");

... you can try something like this:

const ratingBtns = document.querySelectorAll(".rating");
// note that Btns stand for buttons since there is more than 1 button here!

For the for loop, I suggest using classList instead of className so that you can easily add or remove a class instead of changing the className attribute directly. I also don't think selected needs querySelectorAll since there's only one button being selected. You can try this:

for(let i = 0; i < rating.length; i++) {
    rating[i].addEventListener("click", function() {
        let selected = document.querySelector(".selected");
        selected.classList.remove("selected")
        this.classList.add("selected");
    });
}

Lastly, instead of having a default score of 1, I would just leave it empty and let the user choose. Sometimes users might accidentally click on the submit before they select the score, and you wouldn't want them to accidentally send a score of 1! Hope this helps you out a bit ๐Ÿ™‚

1

Dytomaโ€ข 570

@Dytoma

Posted

@elaineleung Really appreciate your feedback, I've taken note and I'll apply that to my project and my next projects. Thank you very much.

1
Adrianoโ€ข 33,950

@AdrianoEscarabote

Posted

Hello Dytoma Batogouma, how are you? I truly loved your project's outcome, however I have some advice that I hope you'll find useful:

Para fazer com que o botรฃo de submti funcione apenas quando o usuario selecionar algum numero, podemos fazer isso;

for(let i = 0; i < rating.length; i++) {
    rating[i].addEventListener("click", function() {
        let selected = document.querySelectorAll(".selected");
    selected[0].className = selected[0].className.replace("selected", "");
    this.className += " selected";
    submit.addEventListener("click", function() {
        let ratinNbr = document.querySelector(".selected");
        let finalRating = document.querySelector(".rating");
        let feedback = document.querySelector(".success");
        let form = document.querySelector(".active");
        form.classList.add("unactive");
        finalRating.innerHTML = ratinNbr.innerHTML;
        feedback.className = feedback.className.replace("unactive", "");
        })
    });
}

The remainder is excellent.

I hope it's useful. ๐Ÿ‘

1

Dytomaโ€ข 570

@Dytoma

Posted

@AdrianoEscarabote Thanks Adriano, I'm gonna apply that.

0

Please log in to post a comment

Log in with GitHub
Discord logo

Join our Discord community

Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!

Join our Discord