SuperSimpleDev / javascript-course

834 stars 635 forks source link

Lesson 13 #140

Open Georgeikani opened 3 months ago

Georgeikani commented 3 months ago

How do i generate the Id in product.js. Const product = [{ id: name: }]

okontg commented 3 months ago

use the valuable name of the dataset (productId) in the querySelector, example below.

//product quantity const quantitySelector = document.querySelector(.js-quantity-selector-${productId}).value; const covertToNumber = Number(quantitySelector);

Frimpong-123 commented 2 months ago

use the valuable name of the dataset (productId) in the querySelector, example below.

//product quantity const quantitySelector = document.querySelector(.js-quantity-selector-${productId}).value; const covertToNumber = Number(quantitySelector);

please are you sure this code works cos i have tried that so many times and i am still not getting the results

okontg commented 2 months ago

this is the HTML

and this the JavaScript const cartInputQuantity = document.querySelector(.js-cart-quantity-input-${productId}).value; let newQuantity = Number(cartInputQuantity);

actually, i don't know how you sent your code.

here is the complete code, starting from the 'save link'. the save link, i use selectAll, in the 'save link' gave it a data-set (e.g, data-product-id=${matchingProduct.id}). use the variable name you use for the dataset ( e.g, const productId = saveCartQuantity.dataset.productId;), use the variable name in your input (e.g, const cartInputQuantity = document.querySelector(.js-cart-quantity-input-${productId}).value;)

//--------------------------Javascript document.querySelectorAll('.js-save-cart-quantity') .forEach((saveCartQuantity)=>{ saveCartQuantity.addEventListener('click',()=>{ const productId = saveCartQuantity.dataset.productId;

    const cartInputQuantity = document.querySelector(`.js-cart-quantity-input-${productId}`).value;
    let newQuantity = Number(cartInputQuantity);
  });
});
Georgeikani commented 1 month ago

Hi Okontg thanks for helping out, but it was resolve. is there any means i can reach you either mail or whatsapp i'd really appreciate it

Georgeikani commented 1 month ago

id: "e43638ce-6aa0-4b85-b27f-e1d07eb678c6", },

is how to generate the id i meant