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 and vanilla JavaScript

Chris 740

@chrisbailey85

Desktop design screenshot for the Interactive pricing component coding challenge

This is a solution for...

  • HTML
  • CSS
  • JS
2junior
View challenge

Design comparison


SolutionDesign

Solution retrospective


I've never been very good at maths, so I did have a bit of an issue with the yearly switchover. I couldn't figure any other way to change it back to the monthly fees. Any feedback would be greatly appreciated.

Community feedback

@jordanlewis9

Posted

Hello!

I'm building this project right now, and I came to the solutions for a little bit of inspiration. Yours looks great! I like the checkbox method for toggling the mini-slider, and how much smoother your slider feels than mine right now!

As for your question, one thing I'm considering regarding the back and forth in the yearly prices is to have a "state" variable outside of the event listener. Basically, it's default state is monthly, and when checkbox is clicked, update that to yearly, and so on and so forth.

One thing you could do is, as was done with the monthly costs, have an object that contains each of the yearly prices. So when the user changes from monthly to yearly, you could toggle the change from one object to another, and call the function that renders the price on screen, passing both the current value and the current pricing object being used. IE

const monthlyCost = {...}
const yearlyCost = {...}
if (checkbox.checked) {
updateText(value, yearlyCost)
else {
updateText(value, monthlyCost)
}

Or, if you want to automatically re-calculate yearly to monthly, it'd be (4/3 * yearlyCost) / 12, but there may be some decimal issues with that.

2

Chris 740

@chrisbailey85

Posted

@jordanlewis9 thank you that's a good idea. I might revisit it once I've finished the current challenge I'm doing.

To be honest I found the slider coloured background difficult to do, my first few ideas didn't work. My initial plan was to use the before pseudo-element, then set the width to the range value, but after a bit of Googling I found out you can't access pseudo-element using JS.

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