Hi there @Bob_Oy, and welcome to the community!
You’ve done really well here — this was quite a tough assignment. Your code works great, and you have used forEach()
rather nicely.
In terms of the problem that caused you to use pop()
. Your use of forEach
is correct, but inside it you are building a new string that you then split. When you’ve built the string, you end up with a comma on the end of it. This is ecause for each item in the array, you are running this:
txt = txt + value + ' ('+ index +'),';
and you are not removing the comma at the end of it before you then split it.
In our version — https://github.com/mdn/learning-area/blob/master/javascript/introduction-to-js-1/tasks/arrays/marking.md#task-3 — for each item in the array we build a new array item, then copy it back to the array to replace the original array item.