objects-functions.js 879 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. let myBook = {
  2. title: '1984',
  3. author: 'George Orwell',
  4. pageCount: 326
  5. }
  6. let otherBook = {
  7. title: 'A Peoples History',
  8. author: 'Howard Zinn',
  9. pageCount: 723
  10. }
  11. let getSummary = function(book) {
  12. return {
  13. summary: `${book.title} by ${book.author}`,
  14. pageCountSummary: `${book.title} is ${book.pageCount} pages long.`
  15. }
  16. }
  17. let bookSummary = getSummary(myBook)
  18. let otherBookSummary = getSummary(otherBook)
  19. console.log(bookSummary.pageCountSummary)
  20. // Challenge area
  21. // Create function - take fahrenheit in - return object with all 3
  22. let convertFahrenheit = function (fahrenheit) {
  23. return {
  24. fahrenheit: fahrenheit,
  25. celsius: (fahrenheit - 32) * (5/9),
  26. kelvin: (fahrenheit + 459.67) * (5/9)
  27. }
  28. }
  29. convertedTemp = convertFahrenheit(-50)
  30. console.log(convertedTemp.celsius)
  31. console.log(convertedTemp.kelvin)