I do apologise if a post like this is not allowed, but I had no where else to go. I watched an explanation on YouTube of function parameters, but it did not make sense. I went to YouTube to see if I could get a verbal explanation of functions since I learn better that way. The YouTube video explained that we have to “call the function” by doing mList[i]()
, but how in the world is that calling the function when there is no function here called function mList()? The only function is visitCarnival(mList). Video in question is JavaScript Function Parameters - YouTube
const beer_cost = 6.75;
const burger_cost = 5.00;
const pop_cost = 3.00;
let account_balance = 15.75;
// drink beer
function drink_beer() {
account_balance = account_balance - beer_cost;
console.log(account_balance);
}
// eat a burger
function eat_burger() {
account_balance = account_balance - burger_cost;
console.log(account_balance);
}
//drink pop
function drink_pop(params) {
account_balance = account_balance - burger_cost;
console.log(account_balance);
}
let mealList = [drink_beer, drink_pop, eat_burger, drink_beer];
function visitCarnival(mList) {
for (let i = 0; num = mList.length; i < num; i = i + 1) {
mList[i]()
}
}
visitCarnival(mealList);