Thanks to visit codestin.com
Credit goes to github.com

Skip to content

13e Solution #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 13e
Choose a base branch
from
Open

13e Solution #7

wants to merge 1 commit into from

Conversation

SuperSimpleDev
Copy link
Owner

No description provided.

Copy link

@Ampah01 Ampah01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const cannot be assigned to another variable because it is constant

Copy link

@Frimpong-123 Frimpong-123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please it seems the code for making the select element interactive, is not functioning and i am getting faustrated...please can you do something about it.

@StuartWalker-creator
Copy link

Am just getting frustrated with this code for the select button, I just keep on getting an error that cannot set properties for null (settingvalue)

} else {
cart.push({
productId: productId,
quantity: 1
quantity: quantity

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead productId: productId and quantity: quantity, use shortHand property

productId,
quantity

@@ -72,14 +72,14 @@ document.querySelectorAll('.js-add-to-cart')
const quantitySelector = document.querySelector(
`.js-quantity-selector-${productId}`
);
const quantity = quantitySelector.value;
const quantity = Number(quantitySelector.value);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, I encounter an issue while test the addToCart function. Jasmine showed an error "Can not read property null (reading 'value')" which I traced back to this line in my code. What could have caused it?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Were you able to solve the issue, as i am facing the same one.....so, if you have a solution can you pls share it.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

** I encountered the same TypeError. **
in order to fix the issue, add '|| 1' at end of both the variables assignment.
This works fine for both the jasmine test as well as functions on live server.
const quantitySelector = document.querySelector(.js-quantity-selector-${productId}) || 1
const quantity = Number(quantitySelector.value) || 1

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my case the cart element on page showing NaN.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, I encounter an issue while test the addToCart function. Jasmine showed an error "Can not read property null (reading 'value')" which I traced back to this line in my code. What could have caused it?

I think its because the property is outside the scope of event listener which makes it undefined. Try bringing the document.querySelector('js-quantity-selector-${productId}' ) inside the event listener and i think it will work after that

@StuartWalker-creator
Copy link

StuartWalker-creator commented Jan 7, 2025 via email

@StuartWalker-creator
Copy link

StuartWalker-creator commented Jan 7, 2025 via email

@Dev-musty
Copy link

I checked it, it was all correct. Later i mocked it in jasmine to test the addToCart function

@AY-IMAM
Copy link

AY-IMAM commented Jan 24, 2025

i tried this solution mine is showing cannot access 'quantity' before initialization pls wat is the problem and solution for that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.