Explorar el Código

Finish objects-functions

Signed-off-by: Michael Tang <michael.h.tang@gmail.com>
Michael Tang hace 5 años
padre
commit
c94f7de918
Se han modificado 1 ficheros con 39 adiciones y 0 borrados
  1. 39 0
      objects-functions.js

+ 39 - 0
objects-functions.js

@@ -0,0 +1,39 @@
+let myBook = {
+    title: '1984',
+    author: 'George Orwell',
+    pageCount: 326
+}
+
+let otherBook = {
+    title: 'A Peoples History',
+    author: 'Howard Zinn',
+    pageCount: 723
+}
+
+let getSummary = function(book) {
+
+    return {
+        summary: `${book.title} by ${book.author}`,
+        pageCountSummary: `${book.title} is ${book.pageCount} pages long.`
+    }
+}
+
+let bookSummary = getSummary(myBook)
+let otherBookSummary = getSummary(otherBook)
+
+console.log(bookSummary.pageCountSummary)
+
+// Challenge area
+// Create function - take fahrenheit in - return object with all 3
+
+let convertFahrenheit = function (fahrenheit) {
+    return {
+        fahrenheit: fahrenheit,
+        celsius: (fahrenheit - 32) * (5/9),
+        kelvin: (fahrenheit + 459.67) * (5/9)
+    }
+}
+
+convertedTemp = convertFahrenheit(-50)
+console.log(convertedTemp.celsius)
+console.log(convertedTemp.kelvin)