Tip Calculator

Solution retrospective
Hello!
Well, I've spent a few days in this one fixing js and logic, but this time I guess it is good!
I hope you enjoy it!
Regards!
Please log in to post a comment
Log in with GitHubCommunity feedback
- @correlucas
👾Fala Anderson, tudo bem? Parabéns pelo desafio!
Acabei de ver seu desafio e está funcionando perfeitamente. Uma coisa que eu vi e me chamou a atenção foi a sombra que está um pouco forte, você pode melhorar isso colocando menos
opacity
e maisblur
, aqui um valor bom pra essa sombra:box-shadow: 5px 5px 15px 5px rgb(0 0 0 / 5%);
Um jeito rápido de fazer o design das sombras e depois so copiar e colocar o código é usando alguns sites pra fazer a sombra sem tocar no código, eu gosto mto desse e pode ser util pra vc: https://www.cssmatic.com/box-shadow
👋 Espero ter ajudado e continue no foco!
Marked as helpful - @ErayBarslan
Hey there and nice work! To achieve what you want you can use
addEventListener
to fire on input change withkeyup
(applies after pressing a key) and call your calculation function inside the listener like:document.querySelector("#custom").addEventListener("keyup", function(e) { let percentage = (billValue * Number(e.target.value)) // rest of function ... }
You can name e whatever you want and it basically selects the element
#custom
and target.value gets us the input value.Additional Suggestions:
- You can write one function with parameter instead several functions for each button like
fivePercent() , tenPercent(), ...
:
calculateTip(percent) { let percentage = (billValue * percent) ... rest of function }
As only percent value changes for each button, you can call the same function for different buttons and just change the parameter percent.
- It would be better to use .toFixed() method on amount. On certain outputs value overflows out of calculator on screen.
- You can use focus selector with CSS to apply when clicked the button, so user can visually see which calculation was done like:
button:focus {style}
Marked as helpful - You can write one function with parameter instead several functions for each button like
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