[자바 스크립트] 연습 05

남한탐정김정은·2023년 2월 3일
0

자바스크립트

목록 보기
27/32
post-thumbnail

문제 1

다음 표를 자바스크립트 객체로 나타내시오

속성
이름Nature of Code
가격30000원
저자다니엘 쉬프만
ISBN9788968481901
페이지 수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)

속성
이름돼지삼겹살
무게100g
가격1690원

메소드설명
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);
profile
남한에 놀러온 김..

0개의 댓글