Assessment wanted for Arrays skill test - 9.6.23

Hi everyone!

I’m requesting a view of my solutions for the Test your skills: Arrays exercise.

CodePen Links:
Arrays 1
Arrays 2
Arrays 3
Arrays 4

Feedback is appreciated, thank you!

Hi again @jt_1

Good work! Here are my comments:

  • General note: When using an online editor, you should also include the HTML and CSS. All tasks have a link at the end with the whole downloadable code (HTML, CSS, JS). This makes testing and changing things easier for us.
  • Tasks 1 + 2: :white_check_mark: Correct
  • Task 3: :warning: Mostly correct.
    • You should use const on the loop item (for (const item of myArray) {}). This also reminds us that item is just a temporary variable inside the loop.
    • You correctly created the new elements (itemIndex) in the loop, but they are immediately discarded instead of replacing the existing elements in the loop. Hint: Assign the new element at the correct index of the array. It may be easier to use another type of loop like forEach() where you have access to the index directly in the callback function.
  • Task 4: :warning: Mostly correct. birds.slice(eagleIndex + 1) doesn’t return the array without “Eagles” as asked in the first part of the task. Try console.log() that part to see what you are returning. Hint: Have a look at splice().

If my explanations are unclear, just ask. :slightly_smiling_face:

See you,
Michael

1 Like

Thank you @mikoMK! :slightly_smiling_face:

I’ve re-worked 3 and 4 based on your feedback. I’ll be sure to implement the HTML, CSS as well in future posts!


Arrays 3 (new):
https://codepen.io/jt_1/pen/poqwooZ

Arrays 4 (new):
https://codepen.io/jt_1/pen/KKbqKKe


Using forEach was a little intimidating at first because it’s not really covered in JavaScript First Steps but looks like the concept will be explained more in the JavaScript Building Blocks section. Anyway, I was able to get something working with it, yay!

Let me know your thoughts.


By the way - on the original solution for Arrays 4, I put .slice but actually meant .splice. Whoops lol.

I have no idea what .slice does but when I tested it seemed to show the results needed. (Old solution for reference - https://codepen.io/jt_1/pen/BavpNRJ)

Regardless, I still like my new solution better on the 2nd attempt! :slightly_smiling_face:

Neato! Great improvements.

By the way using filter() in “Array 4” like you did in your first version was fine. But as usual with JS there are multiple ways to solve a problem. :wink:

Understandable. On the plus side there are several methods that operate on every elements of an array that are much easier to understand now that you know how forEach() works. You already used filter() and another one I frequently use is map().

1 Like

Ok got it and thank you so much again for your helpful feedback on this!

1 Like