19.06 · Arrays / Practice · 5 min
Let the food list grow
Finish the original favorite-foods challenge and check that an added food is included.
Activity 6 of 15 in Arrays
JavaScript Basics / 19.06
Let the food list grow
Not started
Finish the original favorite-foods challenge and check that an added food is included.

Read and update values in an array
Work through 4 focused steps. Read the explanation, type each requested change and check it before moving on. Your own code carries forward.
The mini-lesson opens in a new tab. Your own code carries forward; each step has a focused check and an optional hint.
Start mini-lesson(opens in a new tab)4 steps · Saved work · Instant feedback
YOUR TURN
Let the food list grow
Complete Levels I and II of the original food challenge: print each food, then I really love {food}! for that food. Keep pizza, tacos and sushi and the existing output expressions. Repair the loop so all three foods are included, and adding a fourth food works without changing the loop. Expected output has six lines, alternating food and message.
pizza I really love pizza! tacos I really love tacos! sushi I really love sushi!
Keep the starting inputs. Print these lines in this order, without extra output.
Edit JavaScript, then run it. Check Challenge shows which output checks pass or need a fix. Word wrap is enabled.
Ready to checkRun the checks to see your results here.
Your check results
Work in VS Code instead
Copy the starter into a file named practice.js in VS Code. If Node.js is installed, open the terminal in that folder and run node practice.js. Compare the output with the task above. Automated challenge checks are available in the browser editor.
function printFoods(foods) {
for (let i = 0; i < 2; i++) {
console.log(foods[i]);
console.log("I really love " + foods[i] + "!");
}
}
const favoriteFoods = ["pizza", "tacos", "sushi"];
printFoods(favoriteFoods);Need a nudge?
Let the list choose the stopping point
foods.length changes as items are added. A fixed limit such as 2 omits later items. Keep i < foods.length and read the current food as foods[i].
One possible solution
Your code may look different and still be correct. Compare the approach with your own.
Level III: add pasta to favoriteFoods. You should see two more lines without changing the loop. Then replace the foods with your own three favorites. The original source’s short solution only prints food names; this companion also includes the Level II message requested in its prompt.
function printFoods(foods) {
for (let i = 0; i < foods.length; i++) {
console.log(foods[i]);
console.log("I really love " + foods[i] + "!");
}
}
const favoriteFoods = ["pizza", "tacos", "sushi"];
printFoods(favoriteFoods);Ready to try it?
Practice in your browser and see your results.
Progress details
Have a question?
Ask the Code Zone community.
Ask a question in The Code Zone (opens in a new tab)Continue learning

7 days freeTry The Code Zone
THE CODE ZONE COMMUNITY
Your next step is easier together.
Try the community free for 7 days.
No charge during your trial. Choose your plan on Skool.
- Ask questions and get support in the community
- Watch every course video walkthrough
- Find a study buddy in the 24/7 study room
Make the most of your trial with Premium.
Choose Premium on Skool to try Thursday live help sessions. Bring your questions, work through code, and get unstuck together.
Scheduled Thursdays in Eastern Time. Check the Skool calendar for your local date and time.
Have a website account? Sign in