Your for loop is only making a single iteration before you return a value. For example, in the test case lookUpProfile(“Kristian”, “lastName”) your function returns “No such contact”, because in the first iteration where i = 0, contacts[“firstName”] is “Akira”, so since your first if statement checks if “Kristian” is equal to “Akria”, it evaluates to false and then the outer else code block executes and returns “No such contact”.
Once a return statement is executed, the function immediately exits and does not continue iterating through any loop.
Your outer if statement is fine. What you need to think about is where to put “No such contact”.
At what point during your code would you be guaranteed that all objects’ firstName properties have been checked against the name argument passed into the function? Currently, you return “No such contact” if the first object in the contact’s array does not have a firstName matching the name argument. There is only one place it makes sense to return “No such contact” and it is not in the else statement code block where you currently have it.