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
b1mind
b1mind•2y ago
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.
MarkBoots
MarkBoots•2y ago
also i would suggest setting number of people to a default of 1 instead of 0. that way there is no devision by 0
MarkBoots
MarkBoots•2y ago
winniffy
winniffyOP•2y ago
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?
MarkBoots
MarkBoots•2y ago
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">
b1mind
b1mind•2y ago
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
const tipButtons = document.querySelector('.select_grid-container');
tipButtons.addEventListener('click', (e) => {
})
const tipButtons = document.querySelector('.select_grid-container');
tipButtons.addEventListener('click', (e) => {
})
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
winniffy
winniffyOP•2y ago
the custom tip doesn't work in this instance
b1mind
b1mind•2y ago
cause there is nothing to handle it I just didn't have time to add it, you can add it easy enough.
winniffy
winniffyOP•2y ago
it's not originally of type number, i converted to number in my js
MarkBoots
MarkBoots•2y ago
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)
winniffy
winniffyOP•2y ago
ah thanks, i've tried to but javascript doesn't seem to be going for me rn 😂 i'll just look at it much keknervous
Want results from more Discord servers?
Add your server