JavaScript Shopping Cart Tutorial - Part 3/5

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.hostgator.com/c/43399...
★☆★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
    @Telmosampaio4 жыл бұрын

    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 жыл бұрын

    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

    3 жыл бұрын

    @@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
    @tereshatampubolon14844 жыл бұрын

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

  • @StayFlyJW
    @StayFlyJW4 жыл бұрын

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

  • @retardbuster1498
    @retardbuster14982 жыл бұрын

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

  • @dasaltyl3mon972
    @dasaltyl3mon9722 жыл бұрын

    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!

  • @kidbrave_7673
    @kidbrave_76734 жыл бұрын

    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?

  • @giorgiwereteli2104
    @giorgiwereteli21042 жыл бұрын

    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 Жыл бұрын

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

  • @angelleal3005
    @angelleal30053 жыл бұрын

    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.

  • @jordanleo
    @jordanleo4 жыл бұрын

    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!!!

  • @filipstanic4543
    @filipstanic45433 жыл бұрын

    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-powell4 жыл бұрын

    I'm following along great series thanks telmo!

  • @Telmosampaio

    @Telmosampaio

    4 жыл бұрын

    Thank you Joe :)

  • @jasmineyoung1875
    @jasmineyoung1875 Жыл бұрын

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

  • @dilshadshaikh1401
    @dilshadshaikh1401 Жыл бұрын

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

  • @miguelbolanos4838
    @miguelbolanos48383 жыл бұрын

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

  • @inoske3616
    @inoske36163 жыл бұрын

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

  • @CuongPham-us7cl
    @CuongPham-us7cl2 жыл бұрын

    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
    @thienngo29532 жыл бұрын

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

  • @Henji96
    @Henji963 жыл бұрын

    Thank you for making this, it was extremely helpful

  • @louisaldorio7251
    @louisaldorio72514 жыл бұрын

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

  • @lauraganolli2498
    @lauraganolli24984 жыл бұрын

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

  • @Saudavelpro
    @Saudavelpro4 жыл бұрын

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

  • @Telmosampaio

    @Telmosampaio

    4 жыл бұрын

    Obrigado Raphael!!

  • @maverick_deepak
    @maverick_deepak3 жыл бұрын

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

  • @saturnorbit6810
    @saturnorbit68102 жыл бұрын

    How do you round the cart total??

  • @gourridaamr8671
    @gourridaamr86713 жыл бұрын

    It really helped me man i thank you a million time

  • @krishkhera2392
    @krishkhera23922 жыл бұрын

    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

  • @tomasmatusek6292
    @tomasmatusek62922 жыл бұрын

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

  • @cynthiacarlson3670
    @cynthiacarlson36704 жыл бұрын

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

  • @ansuman4233
    @ansuman42333 жыл бұрын

    "Simple and perfect!"

  • @Andy-uj1fe
    @Andy-uj1fe4 жыл бұрын

    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);

  • @chinkenwee9696
    @chinkenwee96963 жыл бұрын

    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

  • @jeevandhumal7289

    @jeevandhumal7289

    2 жыл бұрын

    I am also facing same problem 😅

  • @kshitijkumarsaini9501
    @kshitijkumarsaini95013 жыл бұрын

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

  • @reinhardheydrich314

    @reinhardheydrich314

    3 жыл бұрын

    Learn firebase

  • @imrangas
    @imrangas3 жыл бұрын

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

  • @SmashCoder12
    @SmashCoder12 Жыл бұрын

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

  • @ducquang2167
    @ducquang21673 жыл бұрын

    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

  • @TechnoArt_by_HiraSultani
    @TechnoArt_by_HiraSultani2 жыл бұрын

    Thank you Telmo Sampaio...

  • @Lopsang-mj9qh
    @Lopsang-mj9qh10 ай бұрын

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

  • @shahadopalkar5433

    @shahadopalkar5433

    5 ай бұрын

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

  • @ernestochin1914
    @ernestochin19143 жыл бұрын

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

  • @mayurdayal5467
    @mayurdayal54673 жыл бұрын

    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

  • @SweetSeptember12
    @SweetSeptember122 жыл бұрын

    Great videos! It helps a lot

  • @carloseduardogomes9262
    @carloseduardogomes92622 жыл бұрын

    it help me a lot.

  • @MrTaylor12111
    @MrTaylor121114 жыл бұрын

    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));

  • @storageinfo20
    @storageinfo203 жыл бұрын

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

  • @kennyakins3536

    @kennyakins3536

    3 жыл бұрын

    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.

  • @writbanalim2715
    @writbanalim27152 жыл бұрын

    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

  • @zeb9820
    @zeb98203 жыл бұрын

    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

  • @ameerhamza-pw1vq
    @ameerhamza-pw1vq3 жыл бұрын

    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]); }); });

  • @BubblegumSoup

    @BubblegumSoup

    3 жыл бұрын

    Doesn’t work either

  • @hiahpsasmlte7555
    @hiahpsasmlte75553 жыл бұрын

    Amazing tutorial!!!

  • @larisacostrun888
    @larisacostrun8884 жыл бұрын

    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"

  • @avinash6097
    @avinash60973 жыл бұрын

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

  • @ameerhamza-pw1vq

    @ameerhamza-pw1vq

    3 жыл бұрын

    search in stack overflow

  • @AlanSilva-de4dd
    @AlanSilva-de4dd3 жыл бұрын

    Telmo Sampaio thank you man

  • @sohamdasbiswas.3534
    @sohamdasbiswas.35342 жыл бұрын

    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 жыл бұрын

    @@Jatin-xh7sm no, till now

  • @kurtaaroncabrera3261
    @kurtaaroncabrera32614 жыл бұрын

    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...

  • @lerwinloh3359
    @lerwinloh33594 жыл бұрын

    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

  • @LeonardoF301
    @LeonardoF3014 жыл бұрын

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

  • @jordanleo

    @jordanleo

    4 жыл бұрын

    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

    2 жыл бұрын

    @@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.

  • @patu002
    @patu002 Жыл бұрын

    I got an undefined error in products

  • @muhammadtoqeer6381
    @muhammadtoqeer63812 жыл бұрын

    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 жыл бұрын

    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

  • @gamingxworld8576
    @gamingxworld85763 жыл бұрын

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

  • @tomasmatusek6292

    @tomasmatusek6292

    2 жыл бұрын

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

  • @mohamedaminesadki5542

    @mohamedaminesadki5542

    2 жыл бұрын

    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))

  • @thescorpionsoul2981
    @thescorpionsoul29813 жыл бұрын

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

  • @tuancaovanthanh3911

    @tuancaovanthanh3911

    3 жыл бұрын

    setItems -> setItem ( not "s" )

  • @thescorpionsoul2981

    @thescorpionsoul2981

    3 жыл бұрын

    @@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.

  • @tomasmatusek6292
    @tomasmatusek62922 жыл бұрын

    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)

  • @user-en8vb9th5v

    @user-en8vb9th5v

    2 жыл бұрын

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

  • @sneedltd4801
    @sneedltd48014 жыл бұрын

    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.

  • @gabrieltoledano4507

    @gabrieltoledano4507

    4 жыл бұрын

    I have the same problem did you find anything ?

  • @hayleymogolloncoppel4460

    @hayleymogolloncoppel4460

    3 жыл бұрын

    same!!!

  • @Magistrado1914
    @Magistrado19144 жыл бұрын

    Excellent course 10/08/2020

  • @paperbacky
    @paperbacky3 жыл бұрын

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

  • @Telmosampaio

    @Telmosampaio

    3 жыл бұрын

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

  • @youssefamr9025
    @youssefamr90253 жыл бұрын

    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

    3 жыл бұрын

    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 жыл бұрын

    @@youssifsamirr8209 thank you!

  • @nikitasharma8256

    @nikitasharma8256

    3 жыл бұрын

    @@youssifsamirr8209 THANKS!!

  • @cutiestarlight136

    @cutiestarlight136

    2 жыл бұрын

    @@youssifsamirr8209 thanks bro, u save me there.

  • @zxxza11
    @zxxza114 жыл бұрын

    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

    3 жыл бұрын

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

  • @tomasmatusek6292

    @tomasmatusek6292

    2 жыл бұрын

    @@kennyakins3536 same problem, idnt solution

  • @bubajay7542
    @bubajay75424 жыл бұрын

    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 жыл бұрын

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

  • @ednueljaytongol8179

    @ednueljaytongol8179

    4 жыл бұрын

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

  • @richabajpai6329
    @richabajpai63293 жыл бұрын

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

  • @Telmosampaio

    @Telmosampaio

    3 жыл бұрын

    Hi Richa, you are most welcome :)

  • @fokion20
    @fokion202 жыл бұрын

    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

    Жыл бұрын

    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😅

  • @ely8478
    @ely84784 жыл бұрын

    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 жыл бұрын

    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! :)

  • @joe-powell
    @joe-powell4 жыл бұрын

    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 жыл бұрын

    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 жыл бұрын

    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

    3 жыл бұрын

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

  • @johnyanastacio1107
    @johnyanastacio11074 жыл бұрын

    thank you for the tutorial..Very good

  • @Telmosampaio

    @Telmosampaio

    4 жыл бұрын

    Welcome 😊

  • @HariharakumarBandaru
    @HariharakumarBandaru2 жыл бұрын

    super video thanks for making

  • @matthewj.joseph7818
    @matthewj.joseph78184 жыл бұрын

    You are, truly great.

  • @Telmosampaio

    @Telmosampaio

    4 жыл бұрын

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

  • @rosaoropezacalderon8650
    @rosaoropezacalderon86504 жыл бұрын

    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 жыл бұрын

    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

  • @codingwitharief
    @codingwitharief3 жыл бұрын

    Thank you so much, sir :)

  • @riazulislamrifat9815
    @riazulislamrifat98154 жыл бұрын

    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[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 жыл бұрын

    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

    3 жыл бұрын

    I got the same problem,Did you get solution?

  • @christintm8499
    @christintm84994 жыл бұрын

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

  • @samarthanirmal3875

    @samarthanirmal3875

    4 жыл бұрын

    Use forEach instead bro.

  • @angeloszacharioudakis9052

    @angeloszacharioudakis9052

    4 жыл бұрын

    did you find the solution?

  • @gloriadai400

    @gloriadai400

    4 жыл бұрын

    @@samarthanirmal3875 it works!!!! thanks bro!!

  • @stephencurran5678

    @stephencurran5678

    4 жыл бұрын

    @@samarthanirmal3875 Where do you use forEach?

  • @Gabriel-hx1yh
    @Gabriel-hx1yh3 жыл бұрын

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

  • @crazyboychandu4391

    @crazyboychandu4391

    3 жыл бұрын

    Did u get solution for this problem

  • @fangzftw7952

    @fangzftw7952

    3 жыл бұрын

    @@crazyboychandu4391 did u solve it

  • @rubenmedina7511
    @rubenmedina75114 жыл бұрын

    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 ! !!)

  • @reinhardheydrich314

    @reinhardheydrich314

    3 жыл бұрын

    use tenplate literal,

  • @reinhardheydrich314

    @reinhardheydrich314

    3 жыл бұрын

    *template

  • @reinhardheydrich314

    @reinhardheydrich314

    3 жыл бұрын

    @@theopenstack sure, how can i send u?

  • @reinhardheydrich314

    @reinhardheydrich314

    3 жыл бұрын

    @@theopenstack yes , how can i send?

  • @reinhardheydrich314

    @reinhardheydrich314

    3 жыл бұрын

    @@theopenstack ohh it's find I'll send u link to my drive wait a moment

  • @cypriangrzywnowicz9275
    @cypriangrzywnowicz92753 жыл бұрын

    You are the best!

  • @ClashWithHuzefa
    @ClashWithHuzefa2 жыл бұрын

    Very nice

  • @youssifsamirr8209
    @youssifsamirr82093 жыл бұрын

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

  • @Gabriel-hx1yh

    @Gabriel-hx1yh

    3 жыл бұрын

    hey did u solve this?

  • @youssifsamirr8209

    @youssifsamirr8209

    3 жыл бұрын

    @@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

    2 жыл бұрын

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

  • @youssifsamirr8209

    @youssifsamirr8209

    2 жыл бұрын

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

  • @nwanekachinedu6509
    @nwanekachinedu65092 жыл бұрын

    you're godsent

  • @yannouldab9878
    @yannouldab98783 жыл бұрын

    a life saver

  • @earthlygamer7142
    @earthlygamer7142 Жыл бұрын

    Thank you so much such Allah bless you

  • @toano8855
    @toano88553 жыл бұрын

    thanks for your turtorial bro

  • @Telmosampaio

    @Telmosampaio

    3 жыл бұрын

    You are welcome bro!

  • @stephencurran5678
    @stephencurran56784 жыл бұрын

    kzread.info/dash/bejne/pnl1zpmFZpWtddo.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

  • @murtuzagulambakir6122
    @murtuzagulambakir61223 жыл бұрын

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

  • @KodunityTV
    @KodunityTV Жыл бұрын

    Hi, please add the PayPal, button.

  • @angeloszacharioudakis9052
    @angeloszacharioudakis90524 жыл бұрын

    says that product is undefined

  • @joe-powell

    @joe-powell

    4 жыл бұрын

    show your code

  • @siviwecengani7360
    @siviwecengani7360 Жыл бұрын

    Reference to finish my Hollywood account

  • @skipthegrades2360
    @skipthegrades23603 жыл бұрын

    kice dutch

  • @mahmoudweis924
    @mahmoudweis9244 жыл бұрын

    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

  • @angeloszacharioudakis9052

    @angeloszacharioudakis9052

    4 жыл бұрын

    did you find the solution?

  • @timzeynalov3537
    @timzeynalov35373 жыл бұрын

    not product ! your object name is a products

  • @sarymsikander5251
    @sarymsikander5251 Жыл бұрын

    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[i].addEventListener("click", function() { cartNumbers(products[i]); }) }; RATHER DO: for (let i=0 ; i carts[i].addEventListener("click", function() { cartNumbers(products[i]); }) }; and the issue is solved 😭

  • @uarts5336

    @uarts5336

    Жыл бұрын

    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

    Жыл бұрын

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

  • @iqmatolaniyan8728

    @iqmatolaniyan8728

    Жыл бұрын

    wow, thank you so much

  • @patu002

    @patu002

    Жыл бұрын

    thanks bro

  • @nuradlina3410
    @nuradlina34102 жыл бұрын

    i lost here

  • @usamamalik2921
    @usamamalik29212 жыл бұрын

    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)); }

  • @emirkoc3525

    @emirkoc3525

    Жыл бұрын

    thank you

  • @avinash6097
    @avinash60973 жыл бұрын

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

  • @lovelyvanshi5115

    @lovelyvanshi5115

    Ай бұрын

    same please reply

  • @behnamnabati8412
    @behnamnabati84124 жыл бұрын

    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

    3 жыл бұрын

    @@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 жыл бұрын

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

  • @RamyasSharma
    @RamyasSharma4 жыл бұрын

    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 жыл бұрын

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

  • @kristipapaqako8239

    @kristipapaqako8239

    4 жыл бұрын

    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)