Skip to content
Advertisement

Using a for-loop to retrieve elements from an Array

JavaScript
JavaScript

I’m new to JS and keep running into issues for a recent class assignment. I’ve reached out to my professor for help but I’m still not understanding it. For our assignment, I need to use a for-loop to retrieve elements from my beatlesArray and concatenate them into a string variable with this format if the images are clicked : 1. Paul 2. George. To do this I was told NOT to use beatlesArray.join(", ") but cannot figure out how to add the elements in my beatlesNameStr. Would anyone be able to assist?

I tried adding them to the string by using beatlesNameStr += cntr + ". " + addJohn…etc but that didn’t work at all. I’m just confused how exactly to add the elements that are being pushed.

Advertisement

Answer

You are on the right track. Update processImages function like this:

JavaScript

or using ES6 syntax:

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