SuperSimpleDev / javascript-course

708 stars 568 forks source link

TypeError: Cannot read properties of null (reading 'value' #136

Open Teslimat opened 2 months ago

Teslimat commented 2 months ago

When I tried console.log(quantity) I received the error message "TypeError: Cannot read properties of null (reading 'value') at HTMLButtonElement. (amazon.js:75:46)"

Teslimat commented 2 months ago

Here is a screenshot of my js code. Kindly assist

Screenshot 2024-07-14 at 11 17 27 AM Screenshot 2024-07-14 at 11 17 48 AM
Schemper commented 2 months ago

Hi Teslim, according to the error in your message, the problem appears to be on line 75. The correct code should be:

const quantity = Number(quantitySelector.value)

The difference here is, the value gotten from the quantity selector is converted to number from string. You can check this out. P.S. I am still learning so I might be way off but I was able to check compare my code with yours and since I am a little bit ahead and thought to help.