- Use an if-statement to return a result based on some condition.
- The task can be best solved when checking for the two specific conditions first.
- Remember that missing parameters will be
undefinedand you can check whether a variable isundefinedusing the strict equality operator===.
- Use a default parameter to set the average preparation time in case it was not provided when the function was called.
- Revisit arrays to find out how to determine the number of layers (length of the layers array).
- First, set up two variables to track the amount of noodles and sauce.
Define them with
letso you can change the value later in your code. Also assign an appropriate initial value. - Use a for loop to iterate through the layers.
- If you encounter a
'noodles'or'sauce'layer in your loop, increase the amount stored in the respective variable accordingly. - Use an object to return both results.
- Revisit arrays to find out how to retrieve an element from an array and how to add something the end of an array.
- The index of the last element in an array
aisa.length - 1. - The function should not have an
returnstatement.
- First, calculate the factor that you need to apply to all amounts based on the target portions.
- One way to ensure the arguments is not modified is to use a new object to save the results.
- Use a
for...inloop to go through all the entries in the original recipe and fill the the object accordingly.