Skip to content
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted over 3 years ago

Interactive rating component solution

Mario Lisbona•150
@MarioLisbona
A solution to the Interactive rating component challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


Is it best practice to use the localStorage.setItem() and localStorage.getItem() methods to save a variable so its accessible across multiple html pages?

I set up an eventlistener on the submit div to assign the value of the checked radio box to a variable. I have then used the localStorage.setItem method to make that rating variable available on the next page. i then open the result page using window.location.replace method.

If no radio button is selected, the result.html page will not load. This is great because it means the result page wont load with a null value for the rating.

Im just confused why this is the case without my writing any logic for it not to load unless rating has a value.

submit.addEventListener('click', ()=> {
    let rating = document.querySelector('input[name="rating"]:checked').value;
    
    localStorage.setItem('userRating', rating);
    window.location.replace("./result.html");
});
Code
Loading...

Please log in to post a comment

Log in with GitHub

Community feedback

No feedback yet. Be the first to give feedback on Mario Lisbona's solution.

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

Stay up to datewith new challenges, featured solutions, selected articles, and our latest news

Frontend Mentor

  • Unlock Pro
  • Contact us
  • FAQs
  • Become a partner
  • Use cases

Explore

  • Learning paths
  • Challenges
  • Solutions
  • Articles

Community

  • Discord
  • Guidelines

For companies

  • Hire developers
  • Train developers
© Frontend Mentor 2019 - 2025
  • Terms
  • Cookie Policy
  • Privacy Policy
  • License