소스 검색

Finish objects-method restaurant model

Signed-off-by: Michael Tang <michael.h.tang@gmail.com>
Michael Tang 5 년 전
부모
커밋
c716b35588
1개의 변경된 파일28개의 추가작업 그리고 0개의 파일을 삭제
  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))
+