Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ Challenge: Work with Object Methods | Section
JavaScript Data Structures

bookChallenge: Work with Object Methods

メニューを表示するにはスワイプしてください

Task

You're provided with an object representing a car's details. Your task is to create a method within the object that calculates the car's total price. The car's total cost is calculated by adding the base price and the sum of additional options.

  • Inside the calculateTotalPrice method, use the this keyword to access the car's basePrice.
  • Use the this keyword to access the options (leatherSeats, sunroof, and navigationSystem) from the options object.
  • Calculate the total price by adding the base price and the sum of all options.
  • Log the total price as the method's result.
12345678910111213141516
const car = { make: "Ford", model: "F-150", basePrice: 72000, options: { leatherSeats: 2400, sunroof: 100, navigationSystem: 1650, }, calculateTotalPrice() { const totalPrice = ___ ; console.log("Total price is", totalPrice); }, }; car.calculateTotalPrice();
copy

Expected output:

Total price is 76150
  1. Inside the method, use this.basePrice to access the base price.
  2. Use this.options to access the options object.
  3. You can use the dot notation to access option properties (e.g., this.options.leatherSeats).
1234567891011121314151617181920
const car = { make: "Ford", model: "F-150", basePrice: 72000, options: { leatherSeats: 2400, sunroof: 100, navigationSystem: 1650, }, calculateTotalPrice() { const totalPrice = this.basePrice + this.options.leatherSeats + this.options.sunroof + this.options.navigationSystem; console.log("Total price is", totalPrice); }, }; car.calculateTotalPrice();
copy

すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 1.  11

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

セクション 1.  11
some-alt