Question
The code below adds items to an empty array ( stored in localStorage ), when I swipe right on an item. I can see it
The code below adds items to an empty array (stored in localStorage), when I swipe right on an item. I can see it works using "console.log(empty);". My question is how can I print these items on another html page when it loads?
var empty = new Array(100);
localStorage.setItem("cart", JSON.stringify(empty));
var retrievedData = localStorage.getItem("cart");
var cards2 = JSON.parse(retrievedData);
$(document).ready(function () {
var cards =[
new Tindercardsjs.card(2, 'Adidas', 'shoes, $90', 'images/runners.jpg'),
new Tindercardsjs.card(1, 'Converse', 'shoes, $40.', 'images/converse.jpg'),
new Tindercardsjs.card(0, 'Nike', 'shoes, $55', 'images/nike.jpg'),
];
Tindercardsjs.render(cards, $('#main'), function (event) {
if(event.direction === 'right' && event.cardid==0){
empty.push(0, 'Nike', 'shoes, $55', 'images/nike.jpg');
}else if(event.direction === 'right' && event.cardid==1){
empty.push(1, 'Converse', 'shoes, $40.', 'images/converse.jpg');
}
else if(event.direction === 'right' && event.cardid==2){
empty.push(2, 'Adidas', 'shoes, $90', 'images/runners.jpg');
} else{
""; }
//direction 2 = right to left swipe.
//alert('swipe');
});
});
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started