Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save davidystephenson/05bef565753da12091c5fc7cdc7df950 to your computer and use it in GitHub Desktop.

Select an option

Save davidystephenson/05bef565753da12091c5fc7cdc7df950 to your computer and use it in GitHub Desktop.
const franchises = {
theGodfather: {
book: {
year: 1969,
author: 'Puzo',
title: 'The Godfather'
},
original: {
budget: 7200000,
director: 'Coppola',
title: 'The Godfather'
},
sequel: {
year: 1974,
star: 'Al Pacino',
title: 'The Godfather'
}
},
lordOfTheRings: {
book: {
year: 1954,
author: 'Tolkien',
title: 'The Lord of the Rings'
},
original: {
budget: 93000000,
director: 'Jackson',
title: 'The Fellowship of the Ring',
},
sequel: {
year: 2002,
star: 'Elijah Wood',
title: 'The Two Towers',
}
},
}
function analyze(franchiseKey, partKey, valueKey) {
const franchise = franchises[franchiseKey]
const part = franchise[partKey]
const value = part[valueKey]
console.log('The', valueKey, 'of', part.title, 'is', value)
return value
}
function formatString(value) {
const formatted = value.toUpperCase()
console.log(formatted)
}
function formatNumber(value) {
const formatted = value.toFixed(2)
console.log(`$${formatted}`)
}
const budget = analyze('theGodfather', 'original', 'budget')
formatNumber(budget)
const author = analyze('lordOfTheRings', 'book', 'author')
formatString(author)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment