Question about Loops 2 skill test

I have written code for the Loops 2 skill test two different ways.

One using } else { and the other using if(i === phonebook.length - 1) {.

They both seem to effectively do the same thing. But I want to know, can someone tell is there an advantage to one method or the other?

Here are the links:

Hello @church_craig

since you use the break inside the if then i think both are equal

but to make it better that you set
para.textContent = Name not found;
before the while loop and do the if inside the loop as you did

that will reduce the need that each time the loop did not find the name to set the textContent to name not found

hope that help and have a nice day :slight_smile: