Javascript Shopping cart Uncaught TypeError

  html, javascript, typeerror

I’ve got job interview task – creating food ordering website from mockup.
The task is mostly focused on html and css, but I have to make fully working shopping cart.
I’ve found a helpful tutorial on YouTube (https://www.youtube.com/watch?v=YeFzkC2awTM) but I’m struggling with updating actual price.

I expect to see total price update after deleting element from the shopping cart. Instead, after clicking removing button, I’m getting this error in the console:

Uncaught TypeError: Cannot read property ‘getElementsByClassName’ of undefined
at updateCartTotal (main.js:22)
at HTMLButtonElement. (main.js:15)

I use pastebin because I’ve tried to format code correctly here for 15 minutes and stack overflow still has a problem with it.

Javascript code:
https://pastebin.com/XPYY2yDJ

Code here doesn't work

HTML:
https://pastebin.com/gbNEVEMg

Code here doesn't work

P.S. Also, after clicking button.trash, sometimes it doesn’t remove entire .food element (sometimes just the button or div.note)

Source: Ask Javascript Questions

LEAVE A COMMENT