So I’ve posted here a few times asking about building an inventory. From the help of someone here @Milton I was able to remove items from the database, but it also changed the way I manage items.
this.items['Potion'] = { quantity: 2}
How would it be possible to set the addItem function from this point on?. Because of the change of code I’m unsure how to set this up correctly.
addItem(item) {
let existingKey = Object.keys(this.items).find(
(item) => this.items[item].name === item.name
);
// let existingKey = Object.keys(this.items).find((item) => this.items[newItem] === item)
// console.log(this.items)
console.log(existingKey)
if (existingKey) {
// console.log("key exists");
this.items[item].quantity = this.items[item].quantity + 1;
// this.items[item].quantity += item.quantity;
} else {
return this.items[item]
}
// if (this.items[item].quantity > 1) {
// this.items[item].quantity = this.items[item].quantity + 1;
// } else {
// this.items.push(item)
// }
}
This code doesn’t work but thought I’d post it here anyway. Heres a link to my latest code pen test.
Any help would be much appreciated!!!
Winston