Using objects for lookup - still having issues in 2018!

I have reviewed all threads about this challenge and I think my code is correct (or at least looks exactly like the code of other FCCers who have run their code successfully! But my code is not passing all tests, specifically, these two:
1 - phoneticLookup(“”) should equal undefined
2 - You should not use case, switch, or if statements

I don’t know how to get the lookup to return “undefined” as there is no space for a default. I could have coded in some IF logic but we’re not allowed…help!

My code:

// Setup
function phoneticLookup(val) {
var result = “”;

// Only change code below this line

var lookup {
alpha:“Adams”,
bravo:‘Boston’,
charlie:‘Chicago’,
delta:‘Denver’,
echo:‘Easy’
};

result = lookup[val];

// Only change code above this line
return result;
}

// Change this value to test
phoneticLookup(“charlie”);

It looks like you’re using funky curly quotes?

2 Likes

I tried both - double quotes (what is appearing as funky) and single quotes. Both to no avail.

After some frustration, I copied the exact code from here >>> link and this time it worked. I see no difference and esp important - I don’t see how/where it is assigning “undefined”…!! But now all tests are passing. Argh.

When I copied your code, the single quotes were invalid as well.

1 Like

Make sure you have your keyboard working properly, or if you are typing your code in a word processor that it doesn’t change the character you are typing.

You are keying left and right double quotation marks. These look like this:

“
”

The key you should be typing is just a normal quote:

"

For the single quotes, you are using an apostrophe:

not a single quote:

'

The difference is subtle to the eye, but is a huge issue as those characters are not recognized by the compiler. Like I mentioned before, your keyboard may be typing them funny, but my guess is that you are either copying the code from somewhere that uses a weird font, or you are putting your code in a word processor or other editor that automatically changes what you type into these special formats.

Don’t be using a word processor to type your code.

2 Likes

It appears you’re not assigning the object to the variable. I believe it should be var lookup = {objects};

1 Like

That was it! That was the difference between my code and the one that worked - thanks!