Profile Lookup Why doesn't my code work?

I’d appreciate it if someone could say why my code doesn’t work. I’ve looked at others post on the forum and can see everyone else has used an if statement, but other than that the logic seems to be the same, so I don’t understand where I’ve gone wrong. (I know I’ve gone a bit overboard with declaring variables).


function lookUpProfile(name, prop){

var arrayLength = contacts.length;
var counter = 0;

while (name != contacts[counter].firstName && counter <= arrayLength ) {

switch (counter, prop, name, arrayLength) {
case counter > arrayLength: return “No such contact”
case contacts[counter].hasOwnProperty(prop) == false : return “No such property”;
default: return contacts[counter][prop]


Hey @HugAMale I think you are misunderstanding switch case statement. You should study the lesson on switch case once again.

1 Like


Thanks, for replying.
After looking online where I’ve misunderstood switch is that it can only take in one variable. I don’t think that’s explicitly mentioned in the codecamp lesson. Until now I couldn’t see the difference between switch and if else which is why I wanted to see if I could make it work with switch.

Thanks again it’s been driving me mad thinking I was doing some syntax error.

You can use the switch statement in a different way. Visit this Stackoverflow link and read the second answer.

You might be able to use that method to write the code using switch case.