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

pricing-component-with-toggle

Kakamotobi 160

@Kakamotobi

Desktop design screenshot for the Pricing component with toggle coding challenge

This is a solution for...

  • HTML
  • CSS
  • JS
2junior
View challenge

Design comparison


SolutionDesign

Solution retrospective


Right now, I've hardcoded the numbers in my JS script for the toggle. I tried to instead use Math.trunc, Math.floor, parseInt(), etc. but I wasn't able to get the decimals properly. For example, the result was "199.89" instead of "199.99". I have commented out my attempt in my script. Does anyone know a solution to this?

Community feedback

@avizmarques

Posted

Hi Kakamotobi, great job the app looks very good! :)

In my opinion there is no reason to have to calculate the prices, you can totally hardcode them. In the real world in a case like this you'd either hardcode the 2 options or receive the values from a database. In either case you don't need to calculate them.

In fact, you're not being able to get the right number, simply because the numbers are not being calculated with an algorithm. They took the monthly prices, multiplied them by 12 to get a year amount, then rounded down to give the user a discount. I'm sure you can find an algorithm to convert the monthly prices into the yearly prices if you try really hard, but in my opinion this goes beyond the scope of this exercise.

1

Kakamotobi 160

@Kakamotobi

Posted

@avizmarques

Hi avizmarques, thank you! :)

I realize you're right. I guess I was a bit too indulged in the project, and disregarded how things would be in the real world.

Thanks for your comment!

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