Create a shopping cart using JavaScript. This project tutorial shows how to add all the basic functionality of a shopping cart into a website.
💻Source files: https://github.com/john-smilga/js-cart-setup
Tutorial from Coding Addict. Check out the Coding Addict YouTube channel: https://www.youtube.com/codingaddict
—
Learn to code for free and get a developer job: https://www.freecodecamp.org
Read hundreds of articles on programming: https://medium.freecodecamp.org
And subscribe for new videos on technology every day: https://youtube.com/subscription_center?add_user=freecodecamp
Original source
32 responses to “JavaScript Project Tutorial: Shopping Cart”
Setup Files
https://github.com/john-smilga/js-cart-setup
its too much helpful and your method of coding are much understandable
js file is empty
You are an amazing teacher! Can you please do a backend version of this tutorial?
idk why… but I love your soothing voice.
hi, I have this error: TypeError: fullPath.indexOF is not a function and Im new on javascript, can you help me.
how to remove item sir?
When i click on aad to cart n on the cart nothing happens plzz reply asap
I'm not get output, pls help me
(function(){ const cartInfo=document.getElementById("cart-Info"); const cart=document.getElementById("cart"); cartInfo.addEventListener("click",function(){ cart.classList.toggle("show-cart"); }); })(); (function(){ const cartBtn=document.querySelectorAll(".store-item-icon"); cartBtn.forEach(function(btn){ btn.addEventListener("click",function(event){ //console.log(event.target); if(event.target.parentElement.classList.contains(".store-item-icon")){ let fullPath=event.target.parentElement.previousElementSibling.src; let pos=fullPath.indexOf("img") +3; let partPath=fullPath.slice(pos); const item={}; item.img='img-cart${partPath}'; let name=event.target.parentElement.parentElement.nextElementSibling.children[0].children[0].textContent; item.name=name; let price=event.target.parentElement.parentElement.nextElementSibling.children[0].children[1].textContent; let finalPrice=price.slice(1).trim(); item.price=finalPrice; //console.log(finalPrice); //console.log(name); //console.log(item); const cartItem=document.createElement("div"); cartItem.classList.add( "cart-item", "d-flex", "justify-content-between", "text-capitalize", "my-3"); cartItem.innerHTML='
${item.name}
$ ${item.price}
' ; const cart=document.getElementById("cart"); const total=document.querySelector(".cart-total-container"); cart.insertBefore(cartItem, total); alert("Item added to the cart"); showTotals(); } }); }); function showTotals(){ const total=[]; const items=document.querySelectorAll(".cart-item-price"); items.forEach(function(item){ total.push(parseFloat(item.textContent)); }); //console.log(total); const totalMoney=total.reduce(function(total,item){ total+=item; return total; },0); const finalMoney=totalMoney.toFixed(2); document.getElementById("cart-total").textContent=finalMoney; document.querySelector(".item-total").textContent=finalMoney; document.getElementById("item-count").textContent=total.length; //console.log(totalMoney); } })();
By chance is there a video for the checkout process that takes all the items and displays it on another page with stripe and or paypal implementation?
can any one suggest me or give me the good resources on woocommerce or shopify E-Commerce Store Development ?? I need it asap
Now, got it why everyone should finish w3schools first.
where the arrow funciton ??
Nothing works. Follow/copy letter by letter and nothing works.
thank you
Hey guys, I added rest of the features except checkout, if anyone is interested
You can check it out at https://shimphillip.github.io/grandmas/
source code at https://github.com/shimphillip/grandmas
if want to learn javaScript check this up https://stude.co/504453/javascript-course
Why you didn't do a tutorial from the beginning on exactly how to design that site from 0 ????
Thank you very usefull project !
Please fix your voice…
You Are Awesome , Great And Talented Teacher . i really watched Ur all video . i learnt lots of lots of new things . i have learnt javaScript . i am learning React Because of you .You do Explain Very hard code very easily and properly . thanks you so much bro . i always love to watch ur tutorial . i have happily subscribed Ur channel . You are doing fantastic job . god bless u.
You are not just a Sir to me, you are also an inspiration Very few people have the power to educate everything beyond his knowledge . You do it pretty well.Thanks a lot dear Sir for continuously inspiring me to do my best. Thanks Sir for making my world so perfect. I am so lucky to have a Sir as wonderful as you are. We will always be thankful to you for all the hard work and efforts you have put in, for educating us
Thanks Sir ! #SarvagyaSagar
good practice video, thanks
Is it a good practice to add event listener to each and every item? I don't think it is.
Rather add event to single item and bind the event to the target
very well 🙂 , thanks
******************URGENT DOUBT*****************************
DOES BLCKCHAIN ONLY TRANSFERS MONEY OR IT STORES MONEY(BITCOIN)
IF IT STORES DOES THE AMOUNT INCREASES ,(EX-WE KEEP MONEY IN BANK IT INCREASE IN INTREST AMOUNT) BUT THE CRYPTOCURENCY FLUCTES
I don't think it's a good idea to relay on a folder name – "img" to get the image name on 19:40 . If someon in the future change name of the folder to "image" for example, then code will be broken.
Would've been nice to see some sort of check out integrations with let's say PayPal for example
Cool project with real life functionality. thanks
it is so nice. and if you have a video that implements for bank system using android studio and SQLite i'm so happy. Thank you!
WOW I love this channel. It is very inspiring to me that i started my own channel on Programming Training for new coders in My Country in Local Language (Amharic) and also trying on English as well. Please check out my channel as well and your feedback and support would be great.
Nice!