In this question, shouldn’t the variable inside the find deals function be hotelPrices and not price? price is never established as a variable.
Hey there,
In the findDeals
function, price
is the name of the parameter that the function takes.
A parameter is a temporary variable that can be given to a function when it is defined. When the function is called, whatever values are given to it are called arguments.
For example, lets define a function that takes 2 numbers and adds them together:
function add(num1, num2) {
return num1 + num2;
}
This function has 2 parameters named num1
and num2
. Now let’s call the function:
add(5, 6);
When the function is called, 5
and 6
are the arguments, and the function will return 5 + 6
, which is 11
.
In this quiz, findDeals
is called with hotelPrices.forEach(findDeals)
, and each element in the hotelPrices
array becomes price
.
The .forEach
will iterate through hotelPrices
, so for the first iteration, price
will be 300
, for the 2nd iteration, price
will be 95
, and for the 3rd and last iteration, price
is 130
.
I hope this helps clear things up. Let me know if you have any questions.
Ben