in here if(contacts[i].firstName === name){ is false, so the else is executed, so return "No such contact"; is run, and your function stops without looking at the rest of the array
I’ve checked, it only works good for first object. you’re right on first step if it is false it goes in else block and function stop. so maybe i should remove the else block?
i have changed the position of code now it works fine for all object but only for correct one, if we put wrong input to display “no such contact“ it doesn’t work and says cannot read the properties undefined
so if the name does not match, you return contacts[i][prop]?
you may want to get pen and paper and plan out the steps of the algorithm carefully before writing code, having a logic plan already written is a good starting point before writing code
figure out when to return the proeprty value, when to return "No such property", when to return "No such contact"
yeah, i was wrong here. can you help me how can i do it in better way. I’m stuck in this problem from 4 days i don’t want to use AI i want to do it myself
let’s say we have to find Sherlock:
open the first page, there is Akira, skip it and go to the next page. if there is Sherlock, get it.
else, again go to the next page.
continue this process until name === Sherlock
are you sure you want to also check contacts[contacts.length]? is there something there?
ok, now, sometimes you find the name, but the property is not there, so you need to adapt the code so that you do not return undefined, but return No such property, there are many ways to do it, as long as you find one that works that’s fine