I am working on practicing booleans (where in the code below, I’m representing the number of times a fruit is counted, essentially that number will be what they can afford to the price, if that makes sense) and the code I am working on seems to be working, but the conditionals I have set are only returning as false and not as true and vice versa when they are swapped.
I’m just wondering if there is an issue with the logic that I currently have.
Here is the data that I have:
items = {
count: 100,
fruits: [
{ id: 'apple', price: 50 },
{ id: 'orange', price: 200 },
{ id: 'banana', price: 500 }
]
};
});
('returns true if the person can afford the item', function() {
const result = code.affordItem(items, 'apple');
expect(result).to.be.equal(true);
});
('returns false if person cannot afford the item', function() {
const result = code.affordItem(items, 'orange');
expect(result).to.be.equal(false);
Here is the code that I have:
function affordItem(items, itemId) {
if (items.count >= items.fruits.quantity && items.fruits.id === itemId) {
return true;
} else {
return false;
}
}
Any guidance would be much appreciated!