A computed property derives its value when accessed instead of storing an independently assigned value. In a rental form, the read-only rentalPriceAfterDiscount reflects changes to the price and discount fields. section 11.3
Implement the computed value by:
- Defining a JavaScript getter on the Rental class. section 11.3
- Leaving the property uninitialized and not independently settable. section 11.3
- Rendering the result as a display value, formatted with toFixed(2), rather than as an input field. section 11.3
Rental price after discount
The getter computes the original rental price minus the percentage discount: this.rentalPriceBeforeDiscount - this.discount * 0.01 * this.rentalPriceBeforeDiscount. Access it as rental.rentalPriceAfterDiscount. section 11.3
Listing 11.14 The completed implementation of rentalPriceAfterDiscount with rentalPriceAfterDiscount
get rentalPriceAfterDiscount() {
return this.rentalPriceBeforeDiscount -
this.discount * 0.01 * this.rentalPriceBeforeDiscount
}
Shows the completed getter implementation for the rental price after discount. section 11.3

