Understanding "defined" variables
Hi, I'm currently working on a problem with an Array. I was wondering if anyone can explain to me why 'breakfasts' isn't defined - when there is a defined array for this. Is it because it is in the main function and the {, are closed? I'm also unsure of when you need to use the this. ... lists. It's all very confusing! Any feedback on this code would be greatly welcomed: PROBLEM: The array you are given represents the menu of breakfast options available at the hotel. The Chef decided to replace one of the options with "Fluffy Pancakes". Write a program to take the index as input, replace the element with that index with "Fluffy Pancakes", and output the new menu to the console as an array. Sample Input 2 Sample Output [ 'Cinnamon Doughnuts', 'Waffles', 'Fluffy Pancakes', 'Chorizo Burrito', 'French Toast' ] The element with index 2 has been replaced in the output array. CODE (BELOW THE COMMENTS IS WHAT I HAVE WRITTEN) function main() { var breakfasts = ['Cinnamon Doughnuts', 'Waffles', 'Granola', 'Chorizo Burrito', 'French Toast']; var index = parseInt(readLine(), 10) //replace the corresponding element by "Fluffy Pancakes" //output the menu to the console } function cafe (breakfasts, index){ this.breakfasts = breakfasts; this.index = index; }; let newMenu = cafe.breakfasts.splice (index, 1, "Fluffy Pancakes"); console.log(newMenu);