0

Please I need help. The JavaScript code is meant to calculate the total cost of the service as the user clicks on the checkbox

https://code.sololearn.com/Wh3ZqC6tXhpM/?ref=app

9th Mar 2023, 9:52 AM
Clement Benjamin
Clement Benjamin - avatar
5 Réponses
+ 6
There are a few things required to fix your code. However, wouldn't it be better to have the calculation when the user clicks submit? Or what is the function of the button? So you could save the function call until that click and I think many of your problems could be solved.
9th Mar 2023, 10:02 PM
Ausgrindtube
Ausgrindtube - avatar
+ 3
Start with reading this. I think that might put you down the right path for you cart section update. https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_custom_elements The other errors you can fix by adding an if(problemVariableName != null) before trying to get your value or comparing the value (for you discountCode, for exampl).
11th Mar 2023, 11:46 PM
Ausgrindtube
Ausgrindtube - avatar
+ 2
Line 229: "const discountCode = document.querySelector('#discount-code').value;" is the cause of your initial typeError message. There is no HTMLElement with an id of "discount-code". Take a closer look at line 167. There the id includes an underscore, not a dash. And while you are looking at line 167 you need to remove the first id in line 167, it also is causing problems. After you take care of the initial bugs you see there is a similar problem on line 236: "const cart = document.querySelector('#cart');"
12th Mar 2023, 3:30 AM
ODLNT
ODLNT - avatar
+ 1
Thanks, I'll correct the errors. Hopefully that'll be the end of the errors.
12th Mar 2023, 7:37 PM
Clement Benjamin
Clement Benjamin - avatar
0
True but I would have loved to have it display the prices live. Do you have any recommendations?
11th Mar 2023, 6:41 PM
Clement Benjamin
Clement Benjamin - avatar