Help Wanted for Array 3

Hi, I am having a little bit of challenge with this particular exercise, I am a little bit confused. I have given my best but seems something wasn’t clicking. Though here is my solution, Array 3 Solution Codepen

Link to Excercise

Kindly give your feedback. Thanks in advance :pray:

Hello @Olixpin

The pop() and push() code is correct. :tada:

Regarding the loop:
Your first step to create the new element inside the loop is correct. The line // Don't edit the code below here! does also mean we are not allowed to copy this code into our own code. These “untouchable” lines of code tell us the exercise expects a single string of all the data from the array inside the variable myString.

I took the correct parts of your loop and added some pseudo code to help you understand the steps:

for(let i = 0; i < myArray.length; i++) {
  const value = `${myArray[i]} ${i}`
  /* Set the current array element to the new value */
}

/* Use the join() method of the array to create the myString variable */

Try to replace each of my comment lines with a single assignment. The resulting code is simpler than you may think. So don’t think to far. I hope that gives you enough support to solve the tasks. If not, just ask. :slightly_smiling_face:

Happy coding,
Michael

Hi, kindly check this https://codepen.io/Oleique/pen/BawMzeN?editors=1010

I think I have gotten it now after though study😎

Hi @Olixpin
You’re link is broken and when I copy the text I still see the old version.
Can you please post the link with your improvments?

Thank you! :slightly_smiling_face:
Michael

Oops, :see_no_evil: seems I didn’t save my work.
Here is the link -> https://codepen.io/Oleique/pen/BawMzeN?editors=1011

1 Like

Congratulations on the improvement! Now the code works as expected :medal_sports:

I have just one comment on how you named your variable. It’s a bit confusion that myString is first an array and then gets converted to a string. I think it would be easier to understand if you would use a variable newArray which gets the new elements and then use const myString = newArray.join(' - ').
Of course this isn’t really a problem in this short little exercise, but it’s a important thing to keep in mind when working on bigger projects where you come back after some months and are scratching your head. Your future self will thank you for good variable names in your code. :grin:

Happy coding,
Michael

PS: Your email address is visible in your post. I think it somehow ended up in the optional “name” field of your profile. I recommend removing it.

2 Likes

Well noted!. Thank you so much for the feedback

1 Like