Basic JavaScript - Profile Lookup

Tell us what’s happening:
I test my code manually multiple times, and it works. I ran the test and it doesn’t work. I refresh the page several times but that does not do anything. I checked previous post but I don’t see any issues like mine. So what am I missing?

Your code so far

// Setup
const contacts = [
    firstName: "Akira",
    lastName: "Laine",
    number: "0543236543",
    likes: ["Pizza", "Coding", "Brownie Points"],
    firstName: "Harry",
    lastName: "Potter",
    number: "0994372684",
    likes: ["Hogwarts", "Magic", "Hagrid"],
    firstName: "Sherlock",
    lastName: "Holmes",
    number: "0487345643",
    likes: ["Intriguing Cases", "Violin"],
    firstName: "Kristian",
    lastName: "Vos",
    number: "unknown",
    likes: ["JavaScript", "Gaming", "Foxes"],

function lookUpProfile(name, prop) {
  // Only change code below this line
  for (let i= 0; i<contacts.length; i++){
    if(contacts[i].firstName === name) {
        return contacts[i][prop];
    } else {
        return "No such contact";
  // Only change code above this line

lookUpProfile("Kristian", "lastName");

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36

Challenge: Basic JavaScript - Profile Lookup

Link to the challenge:

The very first time this else block is run, the function stops immediately

Ok. I need to fix that.

When can you say that no contact matches? After you check them all, right? When have you checked them all?

I really don’t need that else until it loops through all?

An else clause always needs to be next to an if, but you don’t need to put that logic into an else.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.