Why my code not work on freeCodeCamp browser?

Tell us what’s happening:
I’ve try this on vsCode and every test work perfectly! Why not here?

Your code so far

// Setup
var 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(i in contacts){
// check if name & prop in contacts
if(contacts[i].firstName === name && prop in contacts[i]){return console.log(contacts[i][prop])} 
// check if prop in contacts
else if (contacts[i].firstName === name && !(prop in contacts[i])){return 'No such property'}
// else
else if (!(name in contacts)){return ' No such contact'}

// Only change code above this line

lookUpProfile("Akira", "likes");

Your browser information:

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

Challenge: Profile Lookup

Link to the challenge:

Your code is somewhat hard to read. I’d recommend putting the body of your if statements on separate lines.

Anywho, your codes doesn’t quite work right.

return console.log(contacts[i][prop])

In this code, you console log the property and then return the console log return code. The console log return code is an error checking value indicating that the console log was successful. You need to remove the console log and instead just return the property.

Also, in this case I’d end the chain of if-else with an else so you know all input is covered.

you have to declare all your variables.
the freecodecamp editor uses strict mode
outside of the freecodecamp, to switch it on add as first line in your editor 'use strict' (quotes included)

1 Like