문제 1
다음 표를 자바스크립트 객체로 나타내시오
속성 | 값 |
---|
이름 | Nature of Code |
가격 | 30000원 |
저자 | 다니엘 쉬프만 |
ISBN | 9788968481901 |
페이지 수 | 620페이지 |
class book {
constructor(name, price, author, ISBN, page){
this.name = name,
this.price = price,
this.author = author,
this.ISBN = ISBN,
this.page = page
}
print(){
console.log(`${this.name}은 ${this.author}가 쓴 책이며,
ISBN은 ${this.ISBN}, 페이지수는 ${this.page}, 가격은 ${this.price}입니다.`);
}
}
let book1 = new book('Nature of Code','30000원','다니엘 쉬프만',9788968481901,'620페이지');
book1.print();
문제 2
다음 표의 객체를 생성할 수 있는 클래스를 만드시오(클래스 이름은 Product)
메소드 | 설명 |
---|
calcualte(무게) | 무게를 기반으로 가격을 계산합니다. |
class Product{
constructor(name, weight, price){
this.name = name,
this.weight = weight,
this.price = price
}
calculate(wantWeight){
let ggg = this.price / this.weight;
console.log(`${Math.round(ggg*wantWeight)}원`);
}
}
let product = new Product('돼지 삼겹살',100,1690);
product.calculate(200);