Hey !
I am running through the code challenges for JS and am currently on Intermediate JS- isTheDinnerVegan.
Prompt : Write a function isTheDinnerVegan()
that takes in an array of food object and returns a boolean value based on whether or not every item in the array has entirely plant
-based origins.
Issue: I believe I accomplished the task using two variants of function syntax because I get the correct output, but Codecademy prompt says it is still in correct. Any Help in trying to understand if I am missing something in my code that Codecademy sees?
code:
// Write your code here:
// .every() filters out based off a condition and returns a boolean value
/*
const isTheDinnerVegan = (arr => {
return arr.every(value =>arr.value === ‘plant’);
}); // Works, but codeCademy says it doesnt.
*/
function isTheDinnerVegan(food) {
return (food.source === ‘plant’) ? true : false;
}
const dinner = [{name: ‘hamburger’, source: ‘meat’}, {name: ‘cheese’, source: ‘dairy’}, {name: ‘ketchup’, source:‘plant’}, {name: ‘bun’, source: ‘plant’}, {name: ‘dessert twinkies’, source:‘unknown’}];
console.log(isTheDinnerVegan(dinner))
// Should print false