
Design comparison
Solution retrospective
Challenges i encountered was trying to figure out how to get the value from the custom tip input , and figured out that i had to add an event listener.
Community feedback
- @IbrahimMuradPosted about 2 months ago
I looked at you code again. It looks a lot better.
Here are some other suggestions for improvements:
-
You should remove
class="tip-btn"
from the custom tip input, this makes this input takes the styles of other buttons. Let it take the common style ofinput[type="number"]
, which you did, but the class ruins it when hovered. -
Add error messages to other inputs, same as number of customers, and for the style, do not be afraid of breaking everything, I found that all inputs of type number are the same, all labels are the same, and all error messages are the same, you will just add other error messages the same way you did with number of people.
-
number of people has more than probable bad inputs, zero, negative, and decimal. So, I would recommend leave it empty in the HTML and fill it based on the input, "can't be zero", "can't be negative", or "must be a whole number".
-
(I am not a js expert but in this project) I found that using
Number
to convert input value into number is much better, ParseFloat was not predictable for me. Numbers in js can be integers and floats, and the input with type number can not accept alphabets, so Number is more convenient. -
Use
const
instead oflet
. Any js styling checker will murder you if it sees your js script, they hate it.
let numOfPeopleValue = parseFloat(numOfPeople.value) || 1; // Default to 1 if invalid if (!numOfPeopleValue) { errorMessage.classList.remove("hidden"); tipTotal.textContent = "$0.00"; total.textContent = "$0.00"; return; }
Regardless of this project, the condition in if statement will always be false, because
parseFloat(numOfPeople.value)
has two boolean options, true if it is a value orfalse
if it isNaN
, but you did add|| 1
, so if it isNaN
, it will become 1, so!numOfPeopleValue
will always befalse
.Marked as helpful0@mikewil245Posted about 2 months ago@IbrahimMurad Thank you for this very detailed observation. I will work on at some point .
1 -
- @IbrahimMuradPosted about 2 months ago
-
You need to add more validations to the inputs, for example,
number of people
can not be negative or decimal values,bill
can not be negative, andcustom tip
can not be negative and can not exceed100
. -
Some styles are not applied, such as the chosen tip button should have a different color to indicate it has been chosen.
Overall, great job. Keep up.
Marked as helpful0 -
Please log in to post a comment
Log in with GitHubJoin 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