Hello everyone, on my study project I want the localstorage data to appear on my new page (on my cart), I have created my html page. I don’t understand the syntax, if I have to put a setItem then getItem, only getItem? I haven’t finished completing the cart.js page
const params = new URLSearchParams(window.location.search);
const id = params.get('id');
const optionLenses = document.getElementById('optionLenses');
let addCart = document.querySelector('.add-card');
fetch(`http://localhost:3000/api/cameras/${id}`)
.then(response => response.json())
.then(data => {
for (let lense of data.lenses) {produit----------
optionLenses.innerHTML += `<option value="${lense}">${lense}</option>`;
}
let product = {
title: data.name,
price: data.price,
lense: optionLenses.value,
}
addCart.addEventListener('click', () => {
localStorage.setItem(data._id, JSON.stringify(product));
document.querySelector('.cart span').textContent = localStorage.length;
})
})
.catch(error => console.log(error))