실습문제 7-9
WEB/TRAINNING 2017. 12. 4. 09:12 |9. book 객체를 만들려고 한다. 이 객체는 title, author, price의 3개의 프로퍼티로 구성되며 각 프로퍼티는 "HTML5", "황기태", 20000으로 각각 초기화 된다
(1) new Object()를 이용하여 book 객체를 작성하고 객체를 출력하라.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | <!DOCTYPE html> <html><head> <meta charset="UTF-8"> <title>book 객체 만들기</title> </head> <body> <h3>book 객체 만들기</h3> <hr> <script> // (1) // book 객체 만들기 var book = new Object(); book.title = "HTML5"; book.author = "황기태"; book.price = 20000; // book 객체 출력 document.write("book : "); document.write(book.title + ", "); document.write(book.author + ", "); document.write(book.price + "<br>"); </script> </body> </html> | cs |
(2) 리터럴 표기법으로 book 객체를 작성하고 객체를 출력하라.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | <!DOCTYPE html> <html><head> <meta charset="UTF-8"> <title>book 객체 만들기</title> </head> <body> <h3>book 객체 만들기</h3> <hr> <script> // (2) // book 객체 만들기 var book = { title : "HTML5", author : "황기태", price : 20000 }; // book 객체 출력 document.write("book : "); document.write(book.title + ", "); document.write(book.author + ", "); document.write(book.price + "<br>"); </script> </body> </html> | cs |