2018-10-12 15:37:13 -04:00
|
|
|
---
|
|
|
|
title: Using Objects for Lookups
|
|
|
|
---
|
2019-07-24 00:59:27 -07:00
|
|
|
# Using Objects for Lookups
|
2018-10-12 15:37:13 -04:00
|
|
|
|
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
---
|
|
|
|
## Solutions
|
2018-10-12 15:37:13 -04:00
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
<details><summary>Solution 1 (Click to Show/Hide)</summary>
|
2018-10-12 15:37:13 -04:00
|
|
|
|
|
|
|
```javascript
|
|
|
|
function phoneticLookup(val) {
|
|
|
|
var result = "";
|
|
|
|
var lookup = {
|
|
|
|
"alpha": "Adams",
|
|
|
|
"bravo": "Boston",
|
|
|
|
"charlie": "Chicago",
|
|
|
|
"delta": "Denver",
|
|
|
|
"echo": "Easy",
|
|
|
|
"foxtrot": "Frank"
|
|
|
|
};
|
2019-07-24 00:59:27 -07:00
|
|
|
// After converting our case statements into object properties you can make use of the variable `result` to let the function return the correct value.
|
2018-10-12 15:37:13 -04:00
|
|
|
|
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
result = lookup[val];
|
|
|
|
// Only change code above this line
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
```
|
2018-10-12 15:37:13 -04:00
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
#### Relevant Links
|
2018-10-12 15:37:13 -04:00
|
|
|
|
|
|
|
- ["JavaScript object basics" - *MDN JavaScript reference*](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Basics)
|
2019-07-24 00:59:27 -07:00
|
|
|
</details>
|
2018-10-12 15:37:13 -04:00
|
|
|
|