Https://codepen.io/pen/

How could solve the loop 2 test

Here is the marking guide for loops 2:

Hi Chris, I know that you responded to this post a while back in February so you may not see my comment. However, I am confused as to why this code was added to the solution for Task 2.

if(i === phonebook.length - 1) {
para.textContent = ‘Name not found in the phonebook’;
}

I don’t understand why this is relevant to the task or why the code in the parentheses needs to be i === phonebook.length - 1. Why are we checking if i is equal to only the last item in the array and not the others?

If we do not check for i === I.length -1 the loop will go past the last item and return empty.but if we check for the last item it will always go back to the previous item after reaching the last item.add me on discord cesa#9381

I just added you on discord. Thanks.