Currently, I am tackling a basic For/in loop exercise as part of a course curriculum I am enrolled in. The exercise involves working with a simple object containing 3 properties and creating a function that takes two parameters - the object name and the item to search for.
After writing my function and comparing it to the solution provided by the instructor, I realized they are identical. However, when testing it out in the console, an error is thrown indicating that the object property is not defined.
Here is the code snippet:
// Question #2:
// Write a function checkBasket() that lets you know if the item is in the basket or not
const amazonBasket = {
glasses: 1,
books: 2,
floss: 100
}
function checkBasket(basket, lookingFor) {
for(item in basket) {
console.log(item);
if(item === lookingFor) {
return `${lookingFor} is in your basket`;
}
}
return `${lookingfor} is not in your basket`;
}
I would greatly appreciate any assistance from the community! Learning has been challenging but rewarding!
Thank you!