Skip to content

Instantly share code, notes, and snippets.

@mmloveaa
Last active December 27, 2015 19:11
Show Gist options
  • Save mmloveaa/bbc77afe212679c5f6f6 to your computer and use it in GitHub Desktop.
Save mmloveaa/bbc77afe212679c5f6f6 to your computer and use it in GitHub Desktop.
A function to display Mottos for Westerosi Houses
// 12/23/2015
// A function to display Mottos for Westerosi Houses
// 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.
// Search the Houses array for a house whose name equals the name passed to motto() and return it
// If none are found, return an empty string.
// My Solution:
// 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"}
];
var targaryen = {name: "Targaryen", motto: "Fire and Blood"};
// Implement the function
function motto(name) {
for (var i=0;i<houses.length; i++){
if(houses[i].name===name){
return houses[i].motto;
}
}
return ""
}
motto("Bolten")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment