-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathA function to display Mottos for Westerosi Houses.js
43 lines (37 loc) · 1.48 KB
/
A function to display Mottos for Westerosi Houses.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
Description:
Given a list of the following major Houses of Westeros and their respective mottos:
var houses = [
{name: "Targaryen", motto: "Fire and Blood"},
{name: "Stark", motto: "Winter is Coming"},
{name: "Bolton", motto: "Our Blades Are Sharp"},
{name: "Greyjoy", motto: "We Do Not Sow"},
{name: "Tully", motto: "Family, Duty, Honor"},
{name: "Arryn", motto: "As High as Honor"},
{name: "Lannister", motto: "Hear Me Roar!"},
{name: "Tyrell", motto: "Growing Strong"},
{name: "Baratheon", motto: "Ours is the Fury"},
{name: "Martell", motto: "Unbowed, Unbent, Unbroken"}
];```
Write a function that, when passed the name of a House, returns its motto. For instance:
motto("Tyrell")
should return
"Growing Strong" ```
If passed an invalid House name, the script should return an empty string.
*/
// Add the Houses to the array
var houses = [
{name: "Targaryen", motto: "Fire and Blood"},
{name: "Stark", motto: "Winter is Coming"},
{name: "Bolton", motto: "Our Blades Are Sharp"},
{name: "Greyjoy", motto: "We Do Not Sow"},
{name: "Tully", motto: "Family, Duty, Honor"},
{name: "Arryn", motto: "As High as Honor"},
{name: "Lannister", motto: "Hear Me Roar!"},
{name: "Tyrell", motto: "Growing Strong"},
{name: "Baratheon", motto: "Ours is the Fury"},
{name: "Martell", motto: "Unbowed, Unbent, Unbroken"}];
function motto(name) {
const search = houses.find(v=>v.name===name)
return search?search.motto:''
}