andronicus
New Coder
Hi
I am doing an exercise and I would like someone's help. I am having an issue accessing an object array's members. I have the following object array declaration:
const dishData = [
{
name: "Italian pasta",
price: 9.55
},
{
name: "Rice with veggies",
price: 8.65
},
{
name: "Chicken with potatoes",
price: 15.55
},
{
name: "Vegetarian Pizza",
price: 6.45
},
]
I am trying to access each member of the object array within a for loop. My following code will not complie:
dishData.forEach(dish) => {
var finalPrice;
if (taxBoolean == true) {
finalPrice = dishData(dish).price * tax;
}
else if (taxBoolean == false) {
finalPrice = dishData(dish).price;
}
else {
console.log("You need to pass a boolean to the getPrices call!");
return;
}
console.log("Dish: ", dishData(dish).name, "Price: $", dishData(dish).finalPrice);
}
}
When I use dishData(dish).price, I mean to access the price property for that loops iterantion of dishData.
Can anyone help me out?
I am doing an exercise and I would like someone's help. I am having an issue accessing an object array's members. I have the following object array declaration:
const dishData = [
{
name: "Italian pasta",
price: 9.55
},
{
name: "Rice with veggies",
price: 8.65
},
{
name: "Chicken with potatoes",
price: 15.55
},
{
name: "Vegetarian Pizza",
price: 6.45
},
]
I am trying to access each member of the object array within a for loop. My following code will not complie:
dishData.forEach(dish) => {
var finalPrice;
if (taxBoolean == true) {
finalPrice = dishData(dish).price * tax;
}
else if (taxBoolean == false) {
finalPrice = dishData(dish).price;
}
else {
console.log("You need to pass a boolean to the getPrices call!");
return;
}
console.log("Dish: ", dishData(dish).name, "Price: $", dishData(dish).finalPrice);
}
}
When I use dishData(dish).price, I mean to access the price property for that loops iterantion of dishData.
Can anyone help me out?