my code doesn't work on live server
i'm seriously so confused, i can't review my javascript code through live server. it's frustrating cos when i deployed to vercel to test, some functions work and others don't in my javascript. i have no idea if this is a me problem or somn.
is anyone kind enough to help review my codebase, please?
github: https://github.com/winniffy/tip-calculator-app-main
live website: https://tip-calculator-app-main-flame.vercel.app/
GitHub
GitHub - winniffy/tip-calculator-app-main
Contribute to winniffy/tip-calculator-app-main development by creating an account on GitHub.
11 Replies
I would try putting the script in the head with
defer
attribute. If you are going to put at the bottom like that it needs to be before the </body>
Also I would look into Event delegation for the click events.also i would suggest setting number of people to a default of 1 instead of 0. that way there is no devision by 0
it now works in firefox, but not chrome
hmm, i wonder what needs to change now
i would do this inside the custom input function, i suppose?
you can set the value within the <input> to 1 and i if it is of type number you can also give it a min attribute
for example
<input type="number" value="1" min="1" max="10">
The way you are checking the event target already lends it self to just changing the click event to the parent vs each one
1 click listener vs 6
like so
it would work the same but you could also simplify it even more by just grabbing the targets innnerHTML and using it too
https://codepen.io/b1mind/pen/MWBPQVx?editors=0010 reduces the lines of codes and checks a lot
the custom tip doesn't work in this instance
cause there is nothing to handle it
I just didn't have time to add it, you can add it easy enough.
it's not originally of type number, i converted to number in my js
correct, all inputs (no matter what input type) will give a string as value in js
you could btw, use
input.valueAsNumber
(something i recently found out)ah thanks, i've tried to but javascript doesn't seem to be going for me rn 😂 i'll just look at it much