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");
@Jesse-06

This comment has been minimized.

Copy link

Jesse-06 commented Mar 17, 2016

Thanks for the help!

@JJcreated

This comment has been minimized.

Copy link

JJcreated commented Mar 21, 2016

cheers

@JJcreated

This comment has been minimized.

Copy link

JJcreated commented Mar 21, 2016

I don't get why that was a solution still though, they kind of just expected you to know that

@lauracpope

This comment has been minimized.

Copy link

lauracpope commented Mar 29, 2016

A special note, is that I had the code correctly written (same as the code on here), and just needed to reload the page to get it to go through (I copied and pasted the code I had before the reload). Somehow it didn't get what I was telling the code to do.

So, if you think your code is right, try reloading the page!!! (it only took me about 45 mins to figure that out - lol)

@Zackyismail

This comment has been minimized.

Copy link

Zackyismail commented Apr 8, 2016

Thanks for sharing the instructions were a little bit confusing
"Convert the switch statement into a lookup table called lookup. Use it to lookup val and assign the associated string to the result variable."

// 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");

@mohitsharma29

This comment has been minimized.

Copy link

mohitsharma29 commented Apr 18, 2016

why is dot notation not working here?

@rob111

This comment has been minimized.

Copy link

rob111 commented May 1, 2016

thank you

@adamgmurray

This comment has been minimized.

Copy link

adamgmurray commented May 2, 2016

Thank you!

@TedBritt

This comment has been minimized.

Copy link

TedBritt commented May 18, 2016

I was in a bad loop! Thanks

@sagar23

This comment has been minimized.

Copy link

sagar23 commented May 24, 2016

thanks alot.. i was stuck on this !!

@terrencepcrowejr

This comment has been minimized.

Copy link

terrencepcrowejr commented Jun 1, 2016

I have the same question as mohit-jarvis-sharma. I was going crazy trying to figure out why it wouldn't work and then just changed from dot notation to bracket notation and it worked. What is that all about?

@deeqoo

This comment has been minimized.

Copy link

deeqoo commented Jun 13, 2016

Thanks for sharing and saving from going nuts... It's good to share and I'm start too... These instructions need some serious re-consideration its most confusing I have seen anywhere online...

@arjungulzzz

This comment has been minimized.

Copy link

arjungulzzz commented Jun 20, 2016

Thanks Man

@marcderix

This comment has been minimized.

Copy link

marcderix commented Jun 27, 2016

You can't use a dot because the property val does'nt exist in the lookup object. You use:

result = lookup[val];

to say: take the argument that is passed into the phoneticLookup function, and use that to find the matching property.

@PabloVent

This comment has been minimized.

Copy link

PabloVent commented Jun 27, 2016

Thanks, I used a similar one which works all the same.

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"
};

// Only change code above this line

result = lookup[val];
return result;
}

@muhsingenius

This comment has been minimized.

Copy link

muhsingenius commented Jun 28, 2016

result = lookup[val];

//this line is confusing. Any explanation from here?

@bravo1c

This comment has been minimized.

Copy link

bravo1c commented Jun 30, 2016

the result is the value (1)"charlie". this then brings back the object for this is (2)Chicago. think of it like a book mark on the information and you using a bookmark to pull that data.

(1)result = (2)lookup[val];

@joufflu

This comment has been minimized.

Copy link

joufflu commented Jul 3, 2016

result is equal in value to the lookup from the variable object we created but derived from the phoeticklookup val. So if the phoneticlookup is "charlie" then we get result is lookup[charlie], that means we have to see our variable lookup which says "Charlie" is "Chicago". So now we have lookup(charlie) = Chicago, which is now result = Chicago. So basically, insert the test value and work "result = lookup[val];" from left to right. ...ok I get it. just had to write out lol :)

@vamenssa

This comment has been minimized.

Copy link

vamenssa commented Jul 14, 2016

Thank you.

@caevinco

This comment has been minimized.

Copy link

caevinco commented Aug 26, 2016

Sometimes is just a small thing. Thank you all.

@kyriediculous

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

Copy link

Hoxtygen commented Nov 1, 2016

Thanks a lot for the solution

@adamorlowskipoland

This comment has been minimized.

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

This comment has been minimized.

Copy link

sebshub commented Nov 14, 2016

Thanks a lot. Cheers!

@Jenson1991

This comment has been minimized.

Copy link

Jenson1991 commented Nov 20, 2016

thann you.

@vincentiusronalto

This comment has been minimized.

Copy link

vincentiusronalto commented Dec 3, 2016

thank you

@grajsb

This comment has been minimized.

Copy link

grajsb commented Dec 5, 2016

This was such a help!! Thank you.

@Ktifak

This comment has been minimized.

Copy link

Ktifak commented Jan 2, 2017

Thank you!

@ugurozcelik

This comment has been minimized.

Copy link

ugurozcelik commented Jan 24, 2017

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

@Alfrick

This comment has been minimized.

Copy link

Alfrick commented Feb 2, 2017

Assisted here, thanks buddies.

@DulajChathuranga

This comment has been minimized.

Copy link

DulajChathuranga commented Mar 27, 2017

Thanks for the solution!

@kgoooo

This comment has been minimized.

Copy link

kgoooo commented Apr 3, 2017

Ahh thank you!!!!

@ExillustX

This comment has been minimized.

Copy link

ExillustX commented Apr 9, 2017

why result = lookup.val; is not working?

@ThisFnCode

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

Copy link

Sisafokker commented Jun 7, 2017

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

result = Lookup[val];

@pwadeveloper

This comment has been minimized.

Copy link

pwadeveloper commented Jun 12, 2017

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

@thecoog

This comment has been minimized.

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

This comment has been minimized.

Copy link

mackyking commented Jun 20, 2017

Thanks dude!!

@djsirena

This comment has been minimized.

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

This comment has been minimized.

Copy link

Maccauhuru commented Jul 12, 2017

Thank you very much!

@omaballah

This comment has been minimized.

Copy link

omaballah commented Jul 18, 2018

Wow, their questions can be confusing at times.

@omaballah

This comment has been minimized.

Copy link

omaballah commented Jul 18, 2018

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

@Karajna

This comment has been minimized.

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...

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