I don't know why my findDroids function cannot reference the result variable within my droids function. When I run this code, I get "result is not defined". Any tips/guidance is greatly appreciated. I'm new to Javascript, so please go easy on me :)
function droids(arr) {
let result = '';
arr.forEach(findDroids);
return result;
}
function findDroids(value, index, arr){
if (arr[index] == "Droids"){
result = "Found Droids!";
} else{
result = "These are not the droids you're looking for."
}
}
// Uncomment these to check your work!
const starWars = ["Luke", "Finn", "Rey", "Kylo", "Droids"]
const thrones = ["Jon", "Danny", "Tyrion", "The Mountain", "Cersei"]
console.log(droids(starWars)) // should log: "Found Droids!"
console.log(droids(thrones)) //should log: "These are not the droids you're looking for."