console.log("Step 1 - " + steps) would log Step 1 - ["Remove the plastic wrapper", "Microwave 45 seconds", "Let cool", "Enjoy!"] each time the for statement iterates.
It says to log each one, with the string "Step 1 - ", "Step 2 - " in front. I don’t understand how to code that. I understand writing functions, and I understand how to write for loops, but putting a loop in a function is what is really confusing.
Okay, let me give you a couple of tips printInstructions([“Remove the plastic wrapper”, “Microwave 45 seconds”, “Let cool”, “Enjoy!”, ]);
This is the function you provided, which is calling an array. You can ignore the stuff in the array for now - defining a variable steps in your function with these strings doesn’t help you.
In your for loop, your condition i < string[i] tells the loop to run when the value of i is less than the value of string[i]. Let’s say i=0, which it does on the first iteration of your loop. You’re asking the function to see if 0 < string[0]. string[0] is "Remove the plastic wrapper, which cannot be compared to a number.
+ serves as a concatenation operator. "Step 1 -" + tells the function to produce a string that starts with “Step 1-” on every loop. How can you modify that code to change the number?
printInstructions([“Remove the plastic wrapper”, “Microwave 45 seconds”, “Let cool”, “Enjoy!”, ]);
^ This was part of the assignment description. I don’t understand how to log the steps if you don’t define them as a variable or something.
As far as how to modify the cod to change the number, I am not sure how to write that code.
If I have a function: testFunction(var) {return var+3}
Then testFunction(5) would return 8.
In your case, the array is being passed into the function. If you write function printInstructions(arr) { then your function will automatically assign those steps to arr.
function printInstructions(arr) { assigns whatever value you input to arr.
So if I run function([“Remove the plastic wrapper”, “Microwave 45 seconds”, “Let cool”, “Enjoy!”, ]), then it automatically does arr=[“Remove the plastic wrapper”, “Microwave 45 seconds”, “Let cool”, “Enjoy!”, ]
Okay, you’re making progress!
Let’s look at your for (let i = 0; i < array[i]; i++) line.
A for statement sets up conditions for a loop of commands. Your conditions are as follows:
The first condition establishes i = 0. This is fairly common in for loops, and yours is correct.
The second condition tells the loop when to run and stop running. You’ve set this to i < array[i]. This does not work, because you are asking the loop to run when 0 < “Remove the plastic wrapper”, as an example.
The third condition establishes actions that run after a loop completes. i++ increases the value of i, and this is correct.
It is only your i < array[i] that is incorrect on this line.