-
-
Save jastuccio/25dbb7f1cd835585c2c1 to your computer and use it in GitHub Desktop.
// 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"); |
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.
Thanks a lot. Cheers!
thann you.
thank you
This was such a help!! Thank you.
Thank you!
thank you it passes but still says unreachable return after return.
Assisted here, thanks buddies.
Thanks for the solution!
Ahh thank you!!!!
why result = lookup.val;
is not working?
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.
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.
Thank you! Like many others I was also missing the:
result = Lookup[val];
thanks dunnno why
result = Lookup[val];
had to b added tho
I DEFINITELY feel like this one was WAY out of left field. I, in no way, felt prepared with even a little of underdstanding.
Thanks dude!!
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.
Thank you very much!
Wow, their questions can be confusing at times.
But I believe it is crafted that way to make one really think.
thank you so much. I sensed that the solution would be quite simple, but could not formulate it clearly...
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");
Thank you! I was stuck on that. I know I had it right, but something was missing.
Thanks a lot for the solution