Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save davidystephenson/8e73878a20a35fb0b28b14b788a5f047 to your computer and use it in GitHub Desktop.

Select an option

Save davidystephenson/8e73878a20a35fb0b28b14b788a5f047 to your computer and use it in GitHub Desktop.
const media = {
theGodfather: {
budget: 7200000,
director: 'Coppola',
title: 'The Godfather'
},
theHobbit: {
author: 'Tolkien',
protagonist: 'Bilbo',
price: 20,
title: 'The Hobbit'
},
theMatrix: {
budget: 63000000,
director: 'Wachowskis',
title: 'The Matrix'
},
watchmen: {
author: 'Moore',
protagonist: 'Rorschach',
price: 30,
title: 'Watchmen'
},
}
function analyze(mediaKey, valueKey) {
const data = media[mediaKey]
const value = data[valueKey]
console.log('The', valueKey, 'of', data.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', 'budget')
formatNumber(budget)
const author = analyze('theHobbit', 'author')
formatString(author)
const director = analyze('theMatrix', 'director')
formatString(director)
const pages = analyze('watchmen', 'price')
formatNumber(pages)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment