-
Notifications
You must be signed in to change notification settings - Fork 780
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
base: 13e
Are you sure you want to change the base?
13e Solution #7
Conversation
There was a problem hiding this 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
There was a problem hiding this 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.
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 |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
Perhaps the element you are trying to select using the DOM is not
present/accessible in that particular file. I think it's better to first
double check the class to make sure that it exists.
…On Sun, Dec 29, 2024, 11:37 Dev-musty ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In 2-copy-of-code/lesson-13/scripts/amazon.js
<#7 (comment)>
:
> @@ -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);
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?
—
Reply to this email directly, view it on GitHub
<#7 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BJXGNTV42H5O54FIYDY3LPD2H6YDJAVCNFSM6AAAAAAYJ26MFCVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDKMRUHEYDEOJXGU>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Perhaps the element you are trying to select using the DOM is not
present/accessible in that particular file. I think it's better to first
double check the class to make sure that it exists.
…On Mon, Jan 6, 2025, 09:42 Stuart Walker ***@***.***> wrote:
Perhaps the element you are trying to select using the DOM is not
present/accessible in that particular file. I think it's better to first
double check the class to make sure that it exists.
On Sun, Dec 29, 2024, 11:37 Dev-musty ***@***.***> wrote:
> ***@***.**** commented on this pull request.
> ------------------------------
>
> In 2-copy-of-code/lesson-13/scripts/amazon.js
> <#7 (comment)>
> :
>
> > @@ -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);
>
> 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?
>
> —
> Reply to this email directly, view it on GitHub
> <#7 (review)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/BJXGNTV42H5O54FIYDY3LPD2H6YDJAVCNFSM6AAAAAAYJ26MFCVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDKMRUHEYDEOJXGU>
> .
> You are receiving this because you commented.Message ID:
> ***@***.***>
>
|
I checked it, it was all correct. Later i mocked it in jasmine to test the addToCart function |
i tried this solution mine is showing cannot access 'quantity' before initialization pls wat is the problem and solution for that |
No description provided.