Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// Setup
function phoneticLookup(val) {
var result = "";
// Only change code below this line
var lookup = {
"alpha":"Adams",
"bravo":"Boston",
"charlie":"Chicago",
"delta":"Denver",
"echo":"Easy",
"foxtrot":"Frank"
};
result = lookup[val];
// Only change code above this line
return result;
}
// Change this value to test
phoneticLookup("charlie");
@vamenssa
Copy link

vamenssa commented Jul 14, 2016

Thank you.

@caevinco
Copy link

caevinco commented Aug 26, 2016

Sometimes is just a small thing. Thank you all.

@kyriediculous
Copy link

kyriediculous commented Oct 16, 2016

Could somebody perhaps explain why this does not work with dot-notation ? Only with bracket-notation? thank you.

@cherokeestewarthart
Copy link

cherokeestewarthart commented Oct 16, 2016

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

// Only change code below this line
var lookup = {
alpha : "Adams",
bravo : "Boston",
charlie:"Chicago",
delta: "Denver",
echo : "Easy",
foxtrot :"Frank"
};
result = Lookup[val];

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

// Change this value to test
phoneticLookup("charlie");

why is this not working? Can someone help?

@abvolatile
Copy link

abvolatile commented Oct 26, 2016

cherokeestewarthart - not sure if you got an answer on this or already figured it out, but there's one tiny error in your code:

result = Lookup[val];

the "L" should not be capitalized

:)

@Hoxtygen
Copy link

Hoxtygen commented Nov 1, 2016

Thanks a lot for the solution

@adamorlowskipoland
Copy link

adamorlowskipoland commented Nov 11, 2016

Can someone explain me why this didn't work?

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

// Only change code below this line
var lookup = {
"alpha": "Adams",
"bravo": "Boston",
"charlie": "Chicago",
"delta": "Denver",
"echo": "Easy",
"foxtrot": "Frank"
};

result += lookup[val];

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

// Change this value to test
phoneticLookup("alpha");


What I'm asking is this line " result += lookup[val]; ".
Using just " = " sign works.
Using " += " don't. Why? I'm concatenating to result two empty strings, what is the difference to one empty string?

PS
It only don't give back the "undefined" value. Every other works perfectly.

@sebshub
Copy link

sebshub commented Nov 14, 2016

Thanks a lot. Cheers!

@Jenson1991
Copy link

Jenson1991 commented Nov 20, 2016

thann you.

@vincentiusronalto
Copy link

vincentiusronalto commented Dec 3, 2016

thank you

@grajsb
Copy link

grajsb commented Dec 5, 2016

This was such a help!! Thank you.

@Ktifak
Copy link

Ktifak commented Jan 2, 2017

Thank you!

@ugurozcelik
Copy link

ugurozcelik commented Jan 24, 2017

thank you it passes but still says unreachable return after return.

@Alfrick
Copy link

Alfrick commented Feb 2, 2017

Assisted here, thanks buddies.

@DulajChathuranga
Copy link

DulajChathuranga commented Mar 27, 2017

Thanks for the solution!

@kgoooo
Copy link

kgoooo commented Apr 3, 2017

Ahh thank you!!!!

@exilvm
Copy link

exilvm commented Apr 9, 2017

why result = lookup.val; is not working?

@ThisFnCode
Copy link

ThisFnCode commented May 4, 2017

A lot of people are asking why result = lookup.val; isn't working.

The simple answer is because val was passed the argument "charlie" which is a string. And result = lookup."charlie"; doesn't make sense in JS.

Even if you were to create a variable called charlie and assign it to the string "charlie"... it would still end up being lookup."charlie" at the end of the day. Which again, does not work.

Hope that clears it up for you guys.

@jo234usa
Copy link

jo234usa commented May 29, 2017

Thanks! I didn't realize they actually wanted us to create a new variable named lookup, then make result equal lookup[val]. I couldn't figure out how to make that work.

@Sisafokker
Copy link

Sisafokker commented Jun 7, 2017

Thank you! Like many others I was also missing the:

result = Lookup[val];

@pwadeveloper
Copy link

pwadeveloper commented Jun 12, 2017

thanks dunnno why
result = Lookup[val];
had to b added tho

@thecoog
Copy link

thecoog commented Jun 19, 2017

I DEFINITELY feel like this one was WAY out of left field. I, in no way, felt prepared with even a little of underdstanding.

@mackyking
Copy link

mackyking commented Jun 20, 2017

Thanks dude!!

@djsirena
Copy link

djsirena commented Jun 22, 2017

var lookup = {

alpha:"Adams",
bravo:"Boston",
charlie:"Chicago",
delta:"Denver",
echo:"Easy",
foxtrot:"Frank"

};

result = lookup[val];

Nothing but the last two conditions are met. I don't know how this code is working for anyone else.

@Maccauhuru
Copy link

Maccauhuru commented Jul 12, 2017

Thank you very much!

@omaballah
Copy link

omaballah commented Jul 18, 2018

Wow, their questions can be confusing at times.

@omaballah
Copy link

omaballah commented Jul 18, 2018

But I believe it is crafted that way to make one really think.

@Karajna
Copy link

Karajna commented Aug 30, 2018

thank you so much. I sensed that the solution would be quite simple, but could not formulate it clearly...

@lbendror
Copy link

lbendror commented Oct 30, 2020

This is the right 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",
foxtrot: "Frank"
};
result = lookup[val]; // Square brackets

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

phoneticLookup("Charlie");

@sabrinamary
Copy link

sabrinamary commented Jan 14, 2022

Thank you! I was stuck on that. I know I had it right, but something was missing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment