Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialjavier compean rios
Full Stack JavaScript Techdegree Graduate 18,668 PointsIs the same?
function addInventory(products, number) {
products[inventory] += number
console.log(${products[inventory]} ${products[name]} added to the inventory
)
};
function addInventory(products, number) {
products.inventory += number
console.log(${products.inventory} ${products.name} added to the inventory
)
};
Why this code don't work in the same way?
1 Answer
Brandon White
Full Stack JavaScript Techdegree Graduate 34,662 PointsHi javier,
If inventory is the name of the property in a products object, then inventory should be wrapped with string quotes if you’re wanting to use bracket notation.
So product[‘inventory’]
, instead of product[inventory]
. product[inventory] suggests that inventory is a variable that (in this case) contains a string as a value.
javier compean rios
Full Stack JavaScript Techdegree Graduate 18,668 Pointsjavier compean rios
Full Stack JavaScript Techdegree Graduate 18,668 PointsThanks!