Exercise and my solutions is below. I was wondering how I cd do this by using forEach without using a variable to store the result. Also any other possible solution is appreciated, so I can learn multiple ways to solve this. thank u!!!
Complete the function holidays that accepts an array of strings and iterates through the array. If the array contains the string "October", return "Happy Halloween". Otherwise, return the string "Have a great day!". Do not use a variable to store the result that you are returning.
function holidays(arr) {
// Do not use a variable to store your result
// ADD CODE HERE
if (arr.includes("October") === true) {
return "Happy Halloween";
} else {
return "Have a great day!";
}
}
// Uncomment these to check your work!
const months = ["April", "May", "June", "October"];
const animals = ["Cats", "Dogs", "Pigs"];
console.log(holidays(months)); // should return: "Happy Halloween"
console.log(holidays(animals)); // should return: "Have a great day!"