Skip to content
Advertisement

How to add a string to an array and return the string

Build a function forLoop. It takes an array as an argument. Start counting from 0, and, using a for loop, add a string to the array 25 times. But not just any string. If your i value is 1, add the string “I am 1 strange loop.”; if your i value is anything else, add the string “I am ${i} strange loops.”. (Remember flow control with if and else? And how do we interpolate i?) Then return the array.

Learning online and am having trouble understanding what is needed to return the array with the string added to it 25 times?

JavaScript

Advertisement

Answer

You’re close. You simply need to push the string to the array, and then return the array at the end.

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement