Ver código fonte

Finish objects-method restaurant model

Signed-off-by: Michael Tang <michael.h.tang@gmail.com>
Michael Tang 5 anos atrás
pai
commit
c716b35588
1 arquivos alterados com 28 adições e 0 exclusões
  1. 28 0
      objects-methods.js

+ 28 - 0
objects-methods.js

@@ -0,0 +1,28 @@
+let restaurant = {
+    name: 'Red Lobster',
+    guestCapacity: 75,
+    guestCount: 0,
+    checkAvailability: function (partySize) {
+        let seatsLeft = this.guestCapacity - this.guestCount
+
+        return partySize <= seatsLeft
+    },
+    seatParty: function (guests) {
+        this.guestCount = this.guestCount + guests
+        console.log(`seating ${guests}, total is now ${this.guestCount}/${this.guestCapacity}.`)
+    },
+    removeParty: function(guests) {
+        this.guestCount = this.guestCount - guests
+        console.log(`${guests} leaving, total is now ${this.guestCount}/${this.guestCapacity}.`)
+    }
+}
+
+// seatParty
+
+// removeParty
+
+restaurant.seatParty(72)
+console.log(restaurant.checkAvailability(4))
+restaurant.removeParty(5)
+console.log(restaurant.checkAvailability(4))
+