Task is to get one of the key values from the object function to print to the console but having a spot of bother.
var chosenColor = function getThingsByColor(color){
var things = {
red: "This is a red thing",
blue: "This is a blue thing",
orange: "This is an orange thing"
};
return things[color] || "Sorry no color found";
}
coonsole.log(chosenColor('red'));
Result is red undefined.
Your function works fine. I'm assuming you don't see the result printed out in the console. Make sure you have the 'All' tab selected for Console in your Dev Tools
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.