JavaScript Shopping Cart Tutorial - Part 3/5

Поділитися
Вставка
  • Опубліковано 4 жов 2024
  • Project files: gum.co/pSpaA
    ★☆★ My Courses: telmoacademy.com/
    ★☆★ Treehouse Discount Code: bit.ly/2FtkrPL
    ★☆★SkillShare 2 Months FREE : skl.sh/2Q2LsTi
    ★☆★ Best Website Hosting:
    partners.hostga...
    ★☆★UDEMY COURSES:
    *The Complete JavaScript Course 2018: bit.ly/2Ci2Fzk
    *Modern JavaScript From The Beginning: bit.ly/2Br13BM
    *JavaScript: Understanding the Weird Parts: bit.ly/2Epdgu2
    *React 16.6 - The Complete Guide (incl. React Router & Redux): bit.ly/2Br2ikq
    *The Complete React Web Developer Course (with Redux): bit.ly/2zXq9IH
    React Front To Back: bit.ly/2STDUPo
    ★☆★Best laptops for Coding:
    Acer Aspire: amzn.to/2FJrOVh
    Macbook Pro 2013: amzn.to/2NbYIUp
    Asus VivoBook Pro: amzn.to/2YgrCUG
    Macbook Pro 2019: amzn.to/2Xzi4qG
    ★☆★Best JavaScript Books
    John Duckett JavaScript: amzn.to/2EAEvkj
    JavaScript Easy Steps: amzn.to/2VRM4sN
    JavaScript Good Parts: amzn.to/2EFul1V
    Eloquent JavaScript: amzn.to/2Quq5qH
    You dont know JavaScript: amzn.to/2K9I9VX
    My Social Media:
    Twitter: / devtelmo
    Instagram: / sampaiotravels

КОМЕНТАРІ • 228

  • @Telmosampaio
    @Telmosampaio  4 роки тому +18

    Guys this video was missing from the playlist, really sorry about that, and thanks for those of you who let me know

    • @riazulislamrifat9815
      @riazulislamrifat9815 4 роки тому

      Hey can you solve my error please??

    • @trishanksingh6110
      @trishanksingh6110 4 роки тому +3

      Hello
      Everything was going good but then now I am getting the error "My cartItems are null" at 9:25.
      Please help
      Thank You

    • @ernestochin1914
      @ernestochin1914 4 роки тому

      @@trishanksingh6110 same problem, did you solve it?

    • @hazemkawas669
      @hazemkawas669 3 роки тому

      thanks man u are really good, but where can I fine the last video pleas ??

    • @memeperson4075
      @memeperson4075 3 роки тому

      @@ernestochin1914 Have you tried copy-pasting the word cartItems and not typing it, that's what I did, seems to work for me.

  • @tereshatampubolon1484
    @tereshatampubolon1484 4 роки тому +19

    I've watched a lot of video tutorials but only this time I can understand clearly. Thanks Telmo!

  • @StayFlyJW
    @StayFlyJW 4 роки тому +3

    I have honestly been looking for this video for over a year now. You are a life saver

  • @sarymsikander5251
    @sarymsikander5251 2 роки тому +4

    FOR THOSE HAVING THE product: undefined ISSUE IN CONSOLE:
    I literally spent the whole day solving the issue and read the code for a zillion times but to no avail.
    What you have to do is, simple add "let " in the for loop you created.
    INSTEAD OF:
    for (i=0 ; i < carts.length ; i++) {
    carts[i].addEventListener("click", function() {
    cartNumbers(products[i]);
    })
    };
    RATHER DO:
    for (let i=0 ; i < carts.length ; i++) {
    carts[i].addEventListener("click", function() {
    cartNumbers(products[i]);
    })
    };
    and the issue is solved 😭

    • @uarts5336
      @uarts5336 2 роки тому

      Hey.....
      Did you solved that problem.... 🥺
      I tried it, bt the result is same 😭,and I need to submit my project tomorrow... Can anyone help me for this problem?

    • @sarymsikander5251
      @sarymsikander5251 2 роки тому

      @@uarts5336 yes i did- so so sorry for the late reply.

    • @iqmatolaniyan8728
      @iqmatolaniyan8728 Рік тому +1

      wow, thank you so much

    • @patu002
      @patu002 Рік тому

      thanks bro

  • @ansuman4233
    @ansuman4233 4 роки тому +4

    "Simple and perfect!"

  • @ameerhamza-pw1vq
    @ameerhamza-pw1vq 3 роки тому +3

    this is for those who got undefined while pass array as object on cartNumber(product) just use foreach instead of for loop due to some reason of index problem ok by hope you fix it if you have problem thanks by
    buy_btn.forEach((btn, index) => {
    btn.addEventListener("click", () => {
    cartNumber(product[index]);
    });
    });

  • @dasaltyl3mon972
    @dasaltyl3mon972 2 роки тому

    Love the accent, and the tutorial was super easy to follow and made learning js so much simpler when you explained it all so clearly and informativly. Love the work keep it up dude!

  • @filipstanic4543
    @filipstanic4543 3 роки тому

    It's better to make a product object inside setItems function every time we call it because, in your case, for every new product we add to the website we would have to ad a new object to the products array. Or we could make products array automatically create new product when the product is clicked. There are numerous ways that would make this solution programmatic/automated, as it actually needs to be in programming.

  • @joe-powell
    @joe-powell 4 роки тому +3

    I'm following along great series thanks telmo!

  • @kidbrave_7673
    @kidbrave_7673 4 роки тому +2

    Telmo Sampaio thank you for the video I absolutely love this video it's exactly what I was looking for as far as building a shopping cart for my project to show employers once this cov-19 ends. :D I did have a newbie question I'm fairly new to js compared to many others I only been working with the language for a few months and I noticed almost every tutorial or concept is something new... is that a normal situation throughout your learning or is it because I'm missing on basic concepts dealing with the language?

  • @chinkenwee9696
    @chinkenwee9696 3 роки тому +2

    Hi, I'm facing a problem. Where during my first click on the button, the console stated "..... are null", and its added to the cart, yet as in the application part, the number added is falling 1 click behind. thanks

  • @giorgiwereteli2104
    @giorgiwereteli2104 2 роки тому

    you know what ?! i dont know who u are , but i love u so much brooo :((( thank uuuu. i was trying add to cart 2 days , and u make my word happpier now . thank u

  • @hemalathahemalatha3645
    @hemalathahemalatha3645 2 роки тому

    You are just amazing. I clearly understand each and every step.thankyou so much.

  • @dilshadshaikh1401
    @dilshadshaikh1401 Рік тому +1

    i am getting error at incart count code is right but its showing undefined

  • @zeb9820
    @zeb9820 3 роки тому +3

    I have a separate page for each product and it only show the first product when i console.log(product); how do i fix this

    • @eduardoboanca
      @eduardoboanca 3 роки тому

      same problem... did you solved it?

    • @scarbelly32
      @scarbelly32 3 роки тому

      I also have the same problem. Did you ever solve it?

    • @eduardoboanca
      @eduardoboanca 3 роки тому

      @@scarbelly32 Nope i still have this problem, i think that a solution might be to do a product gallery where in one page you put every product you, have separated with some text or something

  • @ducquang2167
    @ducquang2167 4 роки тому +2

    Can someone explain me this:
    let cartItems = {
    [product.tag]: product
    }
    what is that for and why he isn't just putting in the product itself into setItem as an value --> it is at 5:48

    • @avinash6097
      @avinash6097 3 роки тому

      array of objects. so that it can later get converted to json string

  • @CuongPham-us7cl
    @CuongPham-us7cl 3 роки тому +1

    hi, your video is great. My object 'inCart' is an array not a number like you did. So could you pls guide me how to store the number of cart items in 'inCart' array?

  • @thienngo2953
    @thienngo2953 2 роки тому

    Telmo, Best Explain ever seen. Thank you so much!

  • @youssefamr9025
    @youssefamr9025 4 роки тому +4

    I am getting an error saying that "My cart items null" in the console. It worked until 8:55. I followed as you did. Can I get a solution?

    • @youssifsamirr8209
      @youssifsamirr8209 4 роки тому +20

      line 64 "console.log("My cart items are", cartItems);" delete it and write it after line 72 "localstorage.setItem("productsInCart", JSON.stringify(cartItems));"
      had the same error and found it this solution that worked for me

    • @egist4121
      @egist4121 3 роки тому +1

      @@youssifsamirr8209 thank you!

    • @nikitasharma8256
      @nikitasharma8256 3 роки тому +1

      @@youssifsamirr8209 THANKS!!

    • @cutiestarlight136
      @cutiestarlight136 3 роки тому +1

      @@youssifsamirr8209 thanks bro, u save me there.

  • @maverick_deepak
    @maverick_deepak 3 роки тому +1

    When I add second product it is showing null in my inCart. Can anybody please help me?

  • @jasmineyoung1875
    @jasmineyoung1875 Рік тому

    Great series, I purchased the files, however I am not seeing a way to add clothing sizes. Can you help?

  • @larisacostrun888
    @larisacostrun888 4 роки тому +1

    At a moment I was like "Dudeee,is not working,there is a bug. What have you done,why is it working on your project but on mine is not, I wrote exactly the same thing" ...waits 2 minutes "Aaaaa.....so this isn't the final version of the function,yeah it makes sense"

  • @inoske3616
    @inoske3616 4 роки тому +1

    Hi telmo,
    I have error in line69 (...cartItems,)
    Plss help. It says unexpected token or syntaxerror.

  • @retardbuster1498
    @retardbuster1498 3 роки тому

    I've learned far more from your contents than my college lecturers. Thank you.

  • @imrangas
    @imrangas 3 роки тому

    Amazing Telmo. Great Work. If this was 2009
    I would give you 50BTC right now.

  • @Lopsang-mj9qh
    @Lopsang-mj9qh Рік тому +1

    I get the data from api and whenever i click on the add to cart button it overwrite the previous one
    Any suggestion??

    • @shahadopalkar
      @shahadopalkar 7 місяців тому

      Bro did you find a solution for this problem I am facing the same.

  • @lerwinloh3359
    @lerwinloh3359 4 роки тому +2

    hi, after buying the full code, i still couldn't grasp on how to add new products in. when I tried, it would always like me to the previous 4 products instead of the new products

    • @crazyboychandu4391
      @crazyboychandu4391 3 роки тому

      Send me code bro

    • @Eruore
      @Eruore 3 роки тому

      Did you later find out how to add more products?
      Cause I'm having the sane issues as yours when I tried to add more products and I click on it it refers me to the previous ones have done

    • @Eruore
      @Eruore 3 роки тому

      @@crazyboychandu4391 check repository in his github you would get the code there

  • @muhammadtoqeer6381
    @muhammadtoqeer6381 3 роки тому +2

    Hi, thanks for this tutorial but I have a problem when I read the product
    values from the database and write in the object it gives an error that the product is undefined,
    where is the problem?

    • @dasaltyl3mon972
      @dasaltyl3mon972 2 роки тому +1

      Re-read your code, cause it could be as simple as a typing mistake or spelling mistake. I've had that happen to me heaps.

    • @newtonw.1937
      @newtonw.1937 2 роки тому

      I have the same problem lol💔💔

    • @krishkhera2392
      @krishkhera2392 2 роки тому

      Me too

    • @krishkhera2392
      @krishkhera2392 2 роки тому

      Bro ye vali query hui solve

  • @mayurdayal5467
    @mayurdayal5467 3 роки тому +1

    Dude why my code is not running? Whenever I click on add cart it displays a message on the console 'The product clicked is undefined' .

    • @ameerhamza-pw1vq
      @ameerhamza-pw1vq 3 роки тому

      same with me i have write same cide but this error is appear

  • @writbanalim2715
    @writbanalim2715 3 роки тому +1

    The
    cartItems[product.tag].inCart +=1;
    line is causing an error for me. " cartItems[product.tag] " becomes undefined no matter what I do. Any solutions?

    • @bilash215
      @bilash215 2 роки тому

      He addressed it at 14:00

  • @fokion20
    @fokion20 2 роки тому +1

    For some reason when I put console.log("The product you clicked is"), product; it gave me undefined, what could be the reason for this since I copied the code exactly how you have it?

    • @sarymsikander5251
      @sarymsikander5251 2 роки тому

      Same issue! How did you solve it?

    • @iqmatolaniyan8728
      @iqmatolaniyan8728 Рік тому

      @@sarymsikander5251 use let before the "i" in your for loop

    • @sarymsikander5251
      @sarymsikander5251 Рік тому

      @@iqmatolaniyan8728 i am the same person who you thanked in another comment XD this is an older comment. when i solved it, i commented the solution later. 😄

    • @iqmatolaniyan8728
      @iqmatolaniyan8728 Рік тому

      @@sarymsikander5251 ohh, I just saw that😅

  • @TechnoArt_by_HiraSultani
    @TechnoArt_by_HiraSultani 3 роки тому

    Thank you Telmo Sampaio...

  • @angelleal3005
    @angelleal3005 4 роки тому

    I am trying to use the same logic on TypeScript but apparently the spread operator does not work as shown here. It keeps telling me that it only works on objects even though I parsed the JSON string from the Local storage into a JSON object.

  • @sohamdasbiswas.3534
    @sohamdasbiswas.3534 3 роки тому +2

    Sir, what would I do if my products are on different web pages?
    just like an example if your index page has no add to cart button and if I click that image it will open a different webpage for details and having add to cart button there then how will I get the product in the cart?

    • @Jatin-xh7sm
      @Jatin-xh7sm 2 роки тому

      Did you find out how to do it? I have the same problem, I have multiple pages with different products but it is not working properly.

    • @sohamdasbiswas.3534
      @sohamdasbiswas.3534 2 роки тому +1

      @@Jatin-xh7sm no, till now

  • @storageinfo20
    @storageinfo20 4 роки тому +1

    Hey guys, is there any one now how we can dynamiclly feed the array with dynamic product.
    Thanks for your help.

    • @kennyakins3536
      @kennyakins3536 4 роки тому +1

      You can create a products api with ExpressJS that adds the products to a database and deploy with Heroku. You can use Firebase Firestore for the database, and with vanilla JS, you can fetch the products, loop the products and display it dynamically by appending it to the DOM.

  • @jordanleo
    @jordanleo 4 роки тому +1

    at 15:57 when you get the error of 'undefined' i do not, it just console logs the item that is already locally stored... please help me!!!

  • @krishkhera2392
    @krishkhera2392 2 роки тому

    In this you have created "products" but many times u have called "product" so where u have made product? I can get that so plz help

  • @Henji96
    @Henji96 3 роки тому

    Thank you for making this, it was extremely helpful

  • @carloseduardogomes9262
    @carloseduardogomes9262 2 роки тому

    it help me a lot.

  • @Minipro12345
    @Minipro12345 Рік тому

    If we want product inner product then ....?

  • @rosaoropezacalderon8650
    @rosaoropezacalderon8650 4 роки тому +4

    Hi! I would like to know, why does my clicked item says it’s “undefined”😔 I tried to follow the whole tutorial but I still have the same problem. I would like very much to have an advice. Greetings from Mexico

    • @Telmosampaio
      @Telmosampaio  4 роки тому

      Hola Rosita, can you send me your code through codepen maybe, and I will have a look :)

    • @gloriadai400
      @gloriadai400 4 роки тому +3

      Oh me too!!!!!! Did you find the solution???? Very confused...

    • @siddheshb.kukade4685
      @siddheshb.kukade4685 4 роки тому

      @@Telmosampaio help I have same problem.

    • @siddheshb.kukade4685
      @siddheshb.kukade4685 4 роки тому

      Rosa

    • @siddheshb.kukade4685
      @siddheshb.kukade4685 4 роки тому

      I got solution your number of divs o products must not be equal to the total number of array index hope this helps

  • @LeonardoF301
    @LeonardoF301 4 роки тому +2

    How did he assign the name of the product into the [product.tag] ? I cant seem to figure that part out

    • @jordanleo
      @jordanleo 4 роки тому +1

      i am having the same problem did you figure it out?

    • @Luchiittooo20
      @Luchiittooo20 4 роки тому

      with [product.tag] you probably wrote "products" instead of "product"

    • @tomasmatusek6292
      @tomasmatusek6292 3 роки тому

      @@Luchiittooo20 no no, i have same problem with cartItems[products.tag].inCart+=1;
      and it not working doesn matter if you write S/ or no, because its about how you added the property.

  • @Saudavelpro
    @Saudavelpro 4 роки тому +1

    Seus vídeos são mto bons, congratulations man.

  • @kurtaaroncabrera3261
    @kurtaaroncabrera3261 4 роки тому +1

    Why does in my undefined code it still has an error? I already followed your code 1 by 1

    • @paraschoudhary8714
      @paraschoudhary8714 3 роки тому

      same problem in my code.. plzz tell me if u got the solution...

  • @gamingxworld8576
    @gamingxworld8576 3 роки тому +1

    Hello, I have an error at this part. In the setItems function it says "Property 'inCart' does not exist on type 'string' "

    • @tomasmatusek6292
      @tomasmatusek6292 3 роки тому

      I have same problem, U solved it or someone else?

    • @mohamedaminesadki5542
      @mohamedaminesadki5542 3 роки тому

      First you should check if your .getItem and .setItem have the same key (in the video we have "productsinCart", try to check it letter by letter), otherwise you can put (cartItems = parseInt(cartItems)) instead of (cartItems = JSON.parse(cartItems))

  • @AlanSilva-de4dd
    @AlanSilva-de4dd 3 роки тому

    Telmo Sampaio thank you man

  • @miguelbolanos4838
    @miguelbolanos4838 3 роки тому

    great video, but how can I add information from a radiobutton in the product list?

  • @usamamalik2921
    @usamamalik2921 2 роки тому +1

    if anyone is new here and facing an Error that products are not adding so here is the code just copy and paste it
    function setItems(product) {
    let productNumbers = localStorage.getItem('cartNumbers');
    productNumbers = parseInt(productNumbers);
    let cartItems = localStorage.getItem('productsInCart');
    cartItems = JSON.parse(cartItems);
    if(cartItems != null) {
    let currentProduct = product.tag;

    if( cartItems[currentProduct] == undefined ) {
    cartItems = {
    ...cartItems,
    [currentProduct]: product
    }
    }
    cartItems[currentProduct].inCart += 1;
    } else {
    product.inCart = 1;
    cartItems = {
    [product.tag]: product
    };
    }
    localStorage.setItem('productsInCart', JSON.stringify(cartItems));
    }

  • @tomasmatusek6292
    @tomasmatusek6292 3 роки тому

    Telmo, ppl have problem wiht you Cod, with .inCart
    HOw solved that?

  • @tomasmatusek6292
    @tomasmatusek6292 3 роки тому +1

    I have problem here:
    setItems(products)---function:
    if (cartItems != null) {
    cartItems[products.tag].inCart += 1;


    } else {
    products.inCart = 1;
    cartItems = {
    [products.tag]: products
    }
    }
    Can someone help my, and explain why it not work? I have problem with this (any property)

    • @Науэль2002
      @Науэль2002 2 роки тому

      Could you solve it? I'm in the same situation lol

  • @gourridaamr8671
    @gourridaamr8671 4 роки тому

    It really helped me man
    i thank you a million time

  • @zxxza11
    @zxxza11 4 роки тому +2

    why when i click on first product i get inCart the number of the item ,, when i click on the sound product i get inCart '011'

    • @L4urensF
      @L4urensF 4 роки тому

      I have the same problem, did you find a solution for this?

    • @kennyakins3536
      @kennyakins3536 4 роки тому

      JavaScript is adding it as a string put a + before the product

    • @tomasmatusek6292
      @tomasmatusek6292 3 роки тому

      @@kennyakins3536 same problem, idnt solution

  • @cynthiacarlson3670
    @cynthiacarlson3670 4 роки тому

    What's the difference between product(at 1:28) and products (at 1:04)

  • @nwanekachinedu6509
    @nwanekachinedu6509 2 роки тому

    you're godsent

  • @earthlygamer7142
    @earthlygamer7142 Рік тому

    Thank you so much such Allah bless you

  • @patu002
    @patu002 Рік тому

    I got an undefined error in products

  • @saturnorbit6810
    @saturnorbit6810 2 роки тому

    How do you round the cart total??

  • @lauraganolli2498
    @lauraganolli2498 4 роки тому

    How can i use JSON? Because i have promblem with the code.

  • @joe-powell
    @joe-powell 4 роки тому +1

    I was doing fine until 6:00, I don't understand what cartItems = {
    [product.tag] : product
    } is or what is declares. like why is it in an array [product.tag]

    • @Telmosampaio
      @Telmosampaio  4 роки тому +1

      If you look ahead 7:36 I show you that [product.tag] : product is going to be a new object with a key of "greytshirt" and value is another object

    • @joe-powell
      @joe-powell 4 роки тому

      @@Telmosampaiothanks for the reply, I was probably not familliar with the syntax. I only learned from codecademy lol but why is it in brackets instead of " "? also the ...cartItems rest operator was new to me. I will have to look into that

    • @Telmosampaio
      @Telmosampaio  4 роки тому +1

      You need to use the brackets because thats the only way you can use the variable in there, if you use " ", you can't inject the value of your product.tag there, the output would be exactly = "product.tag", meanwhile if you use the [product.tag] the output will be exactly = "greyTshirt"

    • @joe-powell
      @joe-powell 4 роки тому

      @@Telmosampaio oh right right! I totally forgot the rules of notations and how variables, parameters, special characters, number or strings with spaces have to be in brackets.

    • @ernestochin1914
      @ernestochin1914 4 роки тому +2

      Telmo Sampaio i have a problem in 9:25 my cartItems are null

  • @HariharakumarBandaru
    @HariharakumarBandaru 3 роки тому

    super video thanks for making

  • @Magistrado1914
    @Magistrado1914 4 роки тому

    Excellent course
    10/08/2020

  • @louisaldorio7251
    @louisaldorio7251 4 роки тому

    wat for is the stringify dude? , its like u send the code like loopings

  • @yannouldab9878
    @yannouldab9878 3 роки тому

    a life saver

  • @christintm8499
    @christintm8499 4 роки тому +1

    When I click on something the console says the clicked item is undefined..? Help

  • @SweetSeptember12
    @SweetSeptember12 3 роки тому

    Great videos! It helps a lot

  • @ClashWithHuzefa
    @ClashWithHuzefa 2 роки тому

    Very nice

  • @Gabriel-hx1yh
    @Gabriel-hx1yh 3 роки тому +1

    help my if statement is not working in inCart it doesn't plus 1

  • @rubenmedina7511
    @rubenmedina7511 4 роки тому +1

    Great video !! But how do i get the array of productos from my html? Here you put it manually ! (Im have started coding since two month ! !!)

  • @hiahpsasmlte7555
    @hiahpsasmlte7555 3 роки тому

    Amazing tutorial!!!

  • @ely8478
    @ely8478 4 роки тому

    Hello, there's two things that I don't understand (i'm a beginner in js, currently learning) :
    First, I'd like to know why you used the operator "..." is it supposed to do something in the code ? In these lines :
    cartItems = {
    ...cartItems,
    [product.tag]: product
    }
    Secondly, what is the use to convert a json to JS object (or the contrary) ?

    • @joe-powell
      @joe-powell 4 роки тому

      @Gabriel Andy Fono I still don't get exactly what is going on with this spread operator.

    • @larisacostrun888
      @larisacostrun888 4 роки тому +2

      There are like a "shortcut". Instead of saying:"take everything what was already selected(take the black t-shirt,the grey one etc) " you just put "..." in that way the compiler will add to the old selected products the new selected one,without writing much code. Hope it helped! :)

  • @ernestochin1914
    @ernestochin1914 4 роки тому

    my cartitems are null i don’t know what are the problem is can anyone help me?

  • @Andy-uj1fe
    @Andy-uj1fe 4 роки тому

    Hello Telmo,
    On your lesson on 2:31, when I do the the CONSOLE.LOG for my object array, all of the items on the object array displays. This is my JS code how can i just display one item at a time?
    let product = document.querySelectorAll(".add-cart");
    var school = [
    {
    name: "Luxury Swiss Crown Watch",
    price: 100,
    inCart: 0
    },
    {
    name:"Vincero The Rogue Watch",
    price: 100,
    inCart: 0
    },
    {
    name:"Biden Mens Watch",
    price: 25,
    inCart: 0
    }
    ];
    for(i=0;i

    • @joe-powell
      @joe-powell 4 роки тому

      because inside function Cartnumbers() { } needs to be function Cartnumbers(school) { }
      function Cartnumbers(school) {
      console.log(school);
      var conelly = localStorage.getItem("Cartnumbers");
      conelly = parseInt(conelly);

  • @avinash6097
    @avinash6097 3 роки тому

    I am getting null on my log after using json.stringify(cartItems). how to resolve this? pleaseeeee HELP!

  • @richabajpai6329
    @richabajpai6329 4 роки тому

    thank you so much sir , you helped me alotttt...

  • @codingwitharief
    @codingwitharief 3 роки тому

    Thank you so much, sir :)

  • @kshitijkumarsaini9501
    @kshitijkumarsaini9501 3 роки тому

    Hey How can I send the data which I fetched from the database to the cart page when a particular product is clicked?

  • @matthewj.joseph7818
    @matthewj.joseph7818 4 роки тому

    You are, truly great.

    • @Telmosampaio
      @Telmosampaio  4 роки тому

      Thank you so much, hope you are enjoying the course :)

  • @youssifsamirr8209
    @youssifsamirr8209 4 роки тому +1

    My (if cartItems != null) function is not working, any solutions?

    • @Gabriel-hx1yh
      @Gabriel-hx1yh 3 роки тому

      hey did u solve this?

    • @youssifsamirr8209
      @youssifsamirr8209 3 роки тому +1

      @@Gabriel-hx1yh line 64 "console.log("My cart items are", cartItems);" delete it and write it after line 72 "localstorage.setItem("productsInCart", JSON.stringify(cartItems));"
      had the same error, found this solution that worked for me

    • @writbanalim2715
      @writbanalim2715 3 роки тому

      @@youssifsamirr8209 Why would a console.log cause the issue though, it doesn't even interfere with the code

    • @youssifsamirr8209
      @youssifsamirr8209 3 роки тому

      @@writbanalim2715 apparently it didn’t work for me and for others but fixed it with the solution above

  • @KodunityTV
    @KodunityTV Рік тому

    Hi, please add the PayPal, button.

  • @sneedltd4801
    @sneedltd4801 4 роки тому

    Hello, I have a big problem. On my website my products are located in different HTML files. like store/products/product_1. In that case the for loop doesn't work and i only get information about the 1st product i have. I tried using local storage but it didn't work.

  • @toano8855
    @toano8855 4 роки тому

    thanks for your turtorial bro

  • @MrTaylor12111
    @MrTaylor12111 4 роки тому

    Hey mate,
    why when you do the following...
    localStorage.setItem("productsInCart", JSON.stringify(cartItems);
    (cartItems));
    does it create the error :- Uncaught Syntax error: missing ) after argument list
    but when is like this
    localStorage.setItem("productsInCart", JSON.stringify(cartItems));
    (cartItems);
    it does not create the error??
    this did not happen with your javascript code but did with mine, has something changed since you uploaded this tutorial?
    Thanks

    • @osama64jilani
      @osama64jilani 4 роки тому

      Dude its localStorage.setItem("productsInCart", JSON.stringify(cartItems));

  • @johnyanastacio1107
    @johnyanastacio1107 4 роки тому

    thank you for the tutorial..Very good

  • @cypriangrzywnowicz9275
    @cypriangrzywnowicz9275 4 роки тому

    You are the best!

  • @siviwecengani7360
    @siviwecengani7360 Рік тому

    Reference to finish my Hollywood account

  • @thescorpionsoul2981
    @thescorpionsoul2981 4 роки тому

    Hey Telmo!
    could you please help me to fix the, Uncaught ReferenceError: setItems is not defined?

    • @tuancaovanthanh3911
      @tuancaovanthanh3911 4 роки тому

      setItems -> setItem ( not "s" )

    • @thescorpionsoul2981
      @thescorpionsoul2981 4 роки тому +1

      @@tuancaovanthanh3911 i have defined it with s..but in the function i did a spelling mistake. so that's where the error was showing.
      Anyway, Thank you so much.

  • @paperbacky
    @paperbacky 4 роки тому

    Sorry how do i get the images used in the project?

    • @Telmosampaio
      @Telmosampaio  4 роки тому +1

      you can use your own, or find the link in the description

  • @bubajay7542
    @bubajay7542 4 роки тому

    i dont get when i put this it won't change it i dont get to see all the info at console
    let cartItems = localStorage.getItem('productsInCart');
    8:20
    someone please explain

    • @ednueljaytongol8179
      @ednueljaytongol8179 4 роки тому +2

      yeah me too try this console.log ("My cartItems are", product); it works but still have errors

    • @ednueljaytongol8179
      @ednueljaytongol8179 4 роки тому +1

      bro also find the missing Letters on your codes to target it properly

  • @timzeynalov3537
    @timzeynalov3537 3 роки тому

    not product ! your object name is a products

  • @riazulislamrifat9815
    @riazulislamrifat9815 4 роки тому

    Can anyone help me why this code is showing
    Uncaught TypeError: Cannot set property 'inCart' of undefined
    at setinCart (script.js:49)
    at Innercart (script.js:46)
    at HTMLHeadingElement. (script.js:23)
    let products=[
    {
    name:"Tshirt-1",
    tag:"Tshirt-1",
    price:150,
    inCart:0
    },
    {
    name:"Tshirt-2",
    tag:"Tshirt-2",
    price:180,
    inCart:0
    },
    ];
    let cart =document.querySelectorAll('#add-cart');
    for (var i = 0; i < cart.length; i++) {
    cart[i].addEventListener('click',()=>{
    Innercart(products[i]);
    });
    }
    function mycart(){
    let productNumber=localStorage.getItem('cartNumber');
    if (productNumber) {
    document.querySelector('#cart span').textContent=productNumber;
    }
    }
    function Innercart(product){
    let productNumber=localStorage.getItem('cartNumber');
    productNumber=parseInt(productNumber);
    if (productNumber) {
    localStorage.setItem('cartNumber',productNumber + 1);
    document.querySelector('#cart span').textContent=productNumber+1;
    }
    else{
    localStorage.setItem('cartNumber',1);
    document.querySelector('#cart span').textContent=1;
    }
    setinCart(product);
    }
    function setinCart(product){
    product.inCart=1;
    let cartItems= {
    [product.tag]:product
    }
    localStorage.setItem("ProductsInCart", JSON.stringify(cartItems));
    }
    mycart();

    • @lukebennett8773
      @lukebennett8773 4 роки тому +1

      Hi Riazul! If you are still struggling to figure out what is going wrong I can try to help?
      It looks like the `product` parameter of the `setInCart()` function is `undefined`. Apologies if you already know this, but the reason you are getting this error: `Uncaught TypeError: Cannot set property 'inCart' of undefined` is because you are trying to set the property `.inCart` on `product` e.g. `product.inCart = 1;`.
      It is likely that the product you are clicking on in the HTML does not have an equal/match in the `products` array you defined at the top, so when you are doing the `for` loop, and passing a specific product to the `innerCart(products[i])` function, the product does not exist in the array. e.g. `innerCart(products[3])` or something like that, and you only have 2 products in the product array.
      Hope that makes sense, if not, or you wanted further help, if you create a Codesandbox then I can give you a hand :) e.g. codesandbox.io/s/elastic-cannon-rvoym?file=/src/index.js or I can view it anywhere so I can take a look, I can see what the problem is.

    • @zenkia7624
      @zenkia7624 4 роки тому

      I got the same problem,Did you get solution?

  • @angeloszacharioudakis9052
    @angeloszacharioudakis9052 4 роки тому

    says that product is undefined

  • @murtuzagulambakir6122
    @murtuzagulambakir6122 3 роки тому

    The day i understood Using Javascript with html = The day i watched this Video

  • @stephencurran5678
    @stephencurran5678 4 роки тому

    ua-cam.com/video/tEAl7L62GEw/v-deo.htmlm20s I get 'null' when I click Add to Cart. Second click adds item. If I click another item, it adds the last item I clicked, second click adds correct item. It's like the sequence is out by 1. What could cause this?

    • @senaity
      @senaity 3 роки тому

      hello man , did you got solution for this?

    • @stephencurran5678
      @stephencurran5678 3 роки тому

      @@senaity I can't actually remember if I did, but I don't think I ever fixed it. This was over a year ago. I had a bit of trouble following this implementation so I think I used a different method for updating the shopping cart.

    • @senaity
      @senaity 3 роки тому

      @@stephencurran5678 hoo, anyway thank you brother

  • @skipthegrades2360
    @skipthegrades2360 3 роки тому

    kice dutch

  • @mahmoudweis924
    @mahmoudweis924 4 роки тому

    hey telmo
    i got this error and i don't know where this error came from
    line 58 = setItems(product);
    line 27 = cartNumbers(products[i]);
    script.js:58 Uncaught SyntaxError: Identifier 'cartItems' has already been declared
    at cartNumbers (VM1076 script.js:58)
    at HTMLAnchorElement.carts.(anonymous function).addEventListener (file:///C:/Users/sm990222/Desktop/Project/js/script.js:27:4)
    cartNumbers @ VM1076 script.js:58
    carts.(anonymous function).addEventListener @ VM1076 script.js:27
    thank you verymuch

  • @nuradlina3410
    @nuradlina3410 2 роки тому

    i lost here

  • @behnamnabati8412
    @behnamnabati8412 4 роки тому +1

    Hi, thanks for this tutorial but I have a problem when I read the product
    values from the database and write in the object it gives an error that the product is undefined,
    where is the problem?

    • @behnamnabati8412
      @behnamnabati8412 4 роки тому

      The problem was solved

    • @EiliSaya
      @EiliSaya 4 роки тому

      @@behnamnabati8412 how you solved the problem?

    • @starryphantasm
      @starryphantasm 3 роки тому

      @@EiliSaya I solved it by declaring a parameter on the function prototype, like instead of setItems(){...}, make it to setItems(item){...}

    • @egist4121
      @egist4121 3 роки тому

      @@starryphantasm i don't undertstand it

    • @starryphantasm
      @starryphantasm 3 роки тому +1

      @@egist4121 write a variable inside the bracket, for example 'item'

  • @RamyasSharma
    @RamyasSharma 4 роки тому +1

    I am getting an error saying that "My cart items null" in the console. It worked until 8:55. I followed as you did. Can I get a solution?

    • @Theaquilexs
      @Theaquilexs 4 роки тому +1

      hey i got the same error ¿did you find a solution?

    • @kristipapaqako8239
      @kristipapaqako8239 4 роки тому +1

      Hello man, i had the same error,did you find the solution?thnx

    • @olivezavrankova1341
      @olivezavrankova1341 4 роки тому

      Ya I had the same problem. Did you find what was wrong?

    • @gheorghestefan-mihai1672
      @gheorghestefan-mihai1672 4 роки тому

      cartItems = {
      [products.tag]:product
      }
      is rezolvation for this error
      because is the tag's productS not product (at singular)

    • @gheorghestefan-mihai1672
      @gheorghestefan-mihai1672 4 роки тому

      @@olivezavrankova1341 cartItems = {
      [products.tag]:product
      }
      is rezolvation for this error
      because is the tag's productS not product (at singular)

  • @avinash6097
    @avinash6097 3 роки тому

    I am getting null on my log after using json.stringify(cartItems). how to resolve this? pleaseeeee HELP!