can’t change result at the bottom
result
is a variable. Do you know how to change the value stored in a variable? If you don’t know how to do this, you should review this lesson:
yessss I know how to change a value in a stored variable, but how will it change ALL of the values if there is going to be a user input?
You need to use the user input val
to select the correct value in the lookup. Do you know how to access a property of an object?
I’m not sure why you added this. This is less correct that the code in your first post.
function phoneticLookup(val) {
// Create a variable for our result
let result = "";
// Create a lookup object
const lookup = {
alpha: "adams",
bravo: "boston",
charlie: "Chicago"
delta: "Denver"
echo: "Easy"
foxtrot: "Frank"
}
// THIS IS WHERE YOU SHOULD UPDATE
// THE VALUE OF 'result'
// Currently you do nothing with the lookup object
// and return the empty string
return result;
}
This is what I have…
function phoneticLookup(val) {
let result = "";
// Only change code below this line
const lookup = {
alpha: 'adams',
bravo: 'Boston',
charlie: 'Chicago',
delta: 'Denver',
echo: 'Easy',
foxtrot: 'Frank',
}
result = lookup.val
// Only change code above this line
return result;
}
phoneticLookup("charlie");
hehe it’s ok. it’s right in your face. You’ll soon realize!
go over the logic of the code:
- initialize var
- create obj
- return var
there has to be something between 2 and 3 otherwise var will be as initialized
Getting close. You cannot use dot notation with variable holding variable names.
Once you fix that, double check the capitalization of your strings
I think I’m stupid. I did all of the other modules with initilizing vars, creating objects and stuff, but I can’t get this one.
You certainly can get this one. You are nearly there. Insulting yourself can be a reaction some people have to frustration, but it doesn’t really help. This stuff is hard. Give yourself a break.
learning something new always makes us feel this way. dont worry there’s a curve to every learning expirience. hang in there
this holds the next clue !
y’all I just don’t know the keywords to look for I guess to know what to use. This is what I have so far…
function phoneticLookup(val) {
let result = "";
// Only change code below this line
const lookup = {
alpha: 'adams',
bravo: 'Boston',
charlie: 'Chicago',
delta: 'Denver',
echo: 'Easy',
foxtrot: 'Frank',
}
result[lookup]
// Only change code above this line
return result;
}
phoneticLookup("charlie");
function phoneticLookup(val) {
let result = "";
// Only change code below this line
const lookup = {
alpha: 'adams',
bravo: 'Boston',
charlie: 'Chicago',
delta: 'Denver',
echo: 'Easy',
foxtrot: 'Frank',
}
result = lookup[val]
// Only change code above this line
return result;
}
phoneticLookup("charlie");
Close. Very close
phoneticLookup("alpha")
should equal the stringAdams
Ah yeah I got that part lol. I guess I just need to figure out keywords and how to know what to apply. After you explained, I understand for THIS problem. But if I were given another one for a new lesson, I would have the same problem if that makes sense. Thanks for your help
Programming is all about practice. I know the keywords because I’ve done this for years. You can get there too
i took code in high school
i get it. its been awhile man
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.