Hi, I seem to have encountered a problem somewhere in my code while working on the Loops 2 skill test.
I haven’t been able to figure out where exactly I went wrong and need your help in solving this problem.
Here’s a link to my work so far on CodePen : https://codepen.io/mitch-ihejirika/pen/xxVLXGG
Thank you!
Hello @mitchellihejirika
-
in your if statment you compare object to string you should use phonebook[i].name
-
you should break after you set the para.textContent
-
you need to reset the i so it start over each time you click the button
-
it would be better if you reset also the para.textcontent so it does not show the last match result if you tried to enter wrong value after right one
check the following code
btn.addEventListener ('click', function() {
i = 0;
para.textContent ="";
while (i < phonebook.length) {
if (input.value === phonebook[i].name) {
para.textContent = `${phonebook[i].name} ${phonebook[i].number}`;
break;
}
i++;
};
})
hope that help and have a nice day 
1 Like
Thank you! This was very helpful. I apologize for the late reply.
you very welcome and do not be sorry 
1 Like