Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Request path contains unescaped characters
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found

Submitted

Tip Calculator App using HTML, CSS, Flexbox, and JavaScript

Allyson S. 190

@allyson-s-code

Desktop design screenshot for the Tip calculator app coding challenge

This is a solution for...

  • HTML
  • CSS
  • JS
2junior
View challenge

Design comparison


SolutionDesign

Solution retrospective


Hi! I'd love any feedback on my HTML, CSS, or JavaScript. I really struggled with the styling of the :checked state for the % buttons and after a lot of research and help from slack channel I switched from buttons to radio inputs. I feel pretty good about it now, except I can't seem to figure out how to remove the :checked state on the tip inputs once the user clicks on the custom tip percent input area. I tried a few versions of this:

customTip.addEventListener("click", function () {
  document
    .querySelectorAll(".percent-input .percent-input.label")
    .classList.remove("checked");
});

Any suggestions would be great! Thanks so much!!! Allyson

Community feedback

turtlecrab 550

@turtlecrab

Posted

Hey great job, it looks really close to the design!

Addressing your question - there are several inaccuracies in your code:

  • your query selector parameter string looks like you are up to grab labels for radio inputs(correct query for this case would be querySelectorAll('.percent-input + label')), but you actually don't need labels, you need to uncheck the inputs themself! So query request here should be simply querySelectorAll('.percent-input')
  • querySelectorAll returns a list of nodes, so you can't just use methods like .classList.remove on it, you need to iterate over the list and do all the stuff in that loop
  • checked is not a class, it's a property of an input, so to remove it we just set it to false

So the working solution I've come up with is:

customTip.addEventListener("click", function () {
  const radioInputs = document.querySelectorAll(".percent-input")
  radioInputs.forEach(input => input.checked = false)
});

I hope that helped!

Marked as helpful

1

Allyson S. 190

@allyson-s-code

Posted

@turtlecrab Thanks so much!!! This was so helpful. At one point I tried querySelectorAll('.percent-input') but I did not understand that it returned a list of nodes and the need for the loop. And that checked acts as a property of input.

Thanks so much for taking the time to provide feedback. I really appreciate it!!!

Allyson

0
turtlecrab 550

@turtlecrab

Posted

@allyson-s-code It's also worth mentioning that querySelectorAll returns not an array but a special NodeList object. Which conveniently has forEach method just like an array, but it doesn't have methods like map, reduce or filter so if we want to use these we need to convert it to an array via Array.from(nodeList) or spread [...nodeList]

I'm really glad my comment did help! I actually just recently learned these dom and query related details, before that I was as confused as you were, so I'm happy to share the knowledge! Also they say the best way to learn something is to teach it :)

Marked as helpful

0
Allyson S. 190

@allyson-s-code

Posted

@turtlecrab thanks so much! I'll try to spread the knowledge as well! :)

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