본문 바로가기

TIL

[JavaScript] 5주차_클래스 생성 연습

// 클래스 연습해보기

class Car { // 클래스 생성
  constructor(modelName, modelYear, type, price) {
    this.modelName = modelName;
    this.modelYear = modelYear;
    this.type = type;
    this.price = price;
  }
  makeNoise() {
    console.log(
      `${this.modelName}는 ${this.modelYear}년식이며 ${this.type}타입이고 ${this.price}만원 입니다.`
    );
  }
}

const car1 = new Car("쏘렌토", "2023", "디젤", "4000");
car1.makeNoise(); //쏘렌토는 2023년식이며 디젤타입이고 4000만원 입니다.

'TIL' 카테고리의 다른 글

[JavaScript] 5주차_클래스 상속  (0) 2023.06.01
TIL 23.05.31  (0) 2023.05.31
TIL 23.05.28  (0) 2023.05.28
TIL 23.05.25  (0) 2023.05.25
TIL 23.05.24  (0) 2023.05.24