0
I started doing the program in JS to have interaction with the front and I got this error. When it is to show the product, it works by showing the product name on the console, but beats this error, I would like to know how to fix
const select = document.querySelectorAll("[data-ordem]");
const shopProduct = [
{
num: 0,
name: 'Bebedouro',
price: 20
},
{
num: 1,
name: 'Massageador para gatos',
price: 15
},
{
num: 2,
name:'Kit Spray com brinquedo de catnip',
price: 40
},
{
num: 3,
name:'Sache de Catnip',
price: 5
}
];
select.forEach((e) => {
let newItem = parseInt(e.dataset.ordem);
e.addEventListener('click', addItem);
function addItem(e){
e.preventDefault();
for(i=0; i <= shopProduct.length; i++){
if(newItem === shopProduct[i].num){
console.log(shopProduct[i].name);
}
}
}
})
I hadn’t thought that way about for, gave me a new way of thinking and still solved my bug, thank you very much.
– Daniel Passos
Great. If the answer was helpful, mark it as correct ;-)
– dfvc
Done. I’m still learning how to use the platform
– Daniel Passos