일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 27 | 28 | 29 | 30 | 31 |
- 입력메소드
- mvc
- 배열
- 페이징
- 권한변경
- 국취제
- github
- 정처기
- 관리자회원조회
- 인코딩
- 검색기능
- 별찍기
- 페이지 재사용
- forward
- Git
- 비밀번호변경
- emmet환경설정
- 국비학원
- 내일배움카드
- 회원정보수정
- 로그아웃
- live server 환경설정
- jdbc설정
- 비밀번호암호화
- 내배카
- 회원탈퇴
- 국민취업지원제도
- jsp기본
- redirect
- jdbc환경설정
- Today
- Total
기록
*60일차 실습 본문
주어진 데이터를 사용해 메뉴테이블을 작성하세요
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@실습문제 - 상속 - 메뉴</title>
<style>
table {border:1px solid black; border-collapse:collapse; margin: 10px 0;}
th, td {border:1px solid black; text-align:center; padding: 5px;}
th:nth-of-type(2) {width: 200px;}
</style>
</head>
<body onload="init();">
<h1>@실습문제 - 상속 - 메뉴</h1>
<h2>메뉴</h2>
<table id="menu-food">
<caption><h3>식사메뉴</h3></caption>
<thead>
<tr>
<th>번호</th>
<th>메뉴명</th>
<th>가격</th>
<th>타입</th>
</tr>
</thead>
<tbody></tbody>
</table>
<table id="menu-drink">
<caption><h3>음료메뉴</h3></caption>
<thead>
<tr>
<th>번호</th>
<th>메뉴명</th>
<th>가격</th>
<th>성인인증</th><!-- input:checkbox로 처리할 것-->
</tr>
</thead>
<tbody></tbody>
</table>
<script>
/**
* 다음 데이터를 처리하기 위한 class를 작성하세요
* (Food와 Drink의 부모클래스 Menu 설계할 것)
*
* Food - id:string, name:string, price:number, type:string
* Drink - id:string, name:string, price:number, adultOnly:boolean
*/
const menuData = {
foodMenu : [
new Food('food101','잡채밥', 8000, '밥'),
new Food('food102','김치찌게', 7500, '밥'),
new Food('food103','로제파스타', 9000, '면'),
new Food('food104','돌솥비빔밥', 8000, '밥'),
new Food('food105','짬뽕', 9000, '면'),
],
drinkMenu : [
new Drink('drink201','생수', 1000, false),
new Drink('drink202','오렌지쥬스', 2500, false),
new Drink('drink203','사이다', 2000, false),
new Drink('drink204','생맥주 500cc', 4000, true),
new Drink('drink205','소주', 4000, true),
]
};
const init = () => {
};
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@실습문제 - 상속 - 메뉴</title>
<style>
table {border:1px solid black; border-collapse:collapse; margin: 10px 0;}
th, td {border:1px solid black; text-align:center; padding: 5px;}
th:nth-of-type(2) {width: 200px;}
</style>
</head>
<body onload="init();"> <!-- 페이지 로딩이 끝나면 load이벤트발생 - init함수 호출 -->
<h1>@실습문제 - 상속 - 메뉴</h1>
<h2>메뉴</h2>
<table id="menu-food">
<caption><h3>식사메뉴</h3></caption>
<thead>
<tr>
<th>번호</th>
<th>메뉴명</th>
<th>가격</th>
<th>타입</th>
</tr>
</thead>
<tbody></tbody>
</table>
<table id="menu-drink">
<caption><h3>음료메뉴</h3></caption>
<thead>
<tr>
<th>번호</th>
<th>메뉴명</th>
<th>가격</th>
<th>성인인증</th><!-- input:checkbox로 처리할 것-->
</tr>
</thead>
<tbody></tbody>
</table>
<script>
const init = () => {
console.log('init : 페이지로딩 완료!');
// 렌더
foodMenuRender(menuData);
drinkMenuRender(menuData);
};
const foodMenuRender = ({foodMenu}) => {
const tbody = document.querySelector("table#menu-food tbody");
tbody.innerHTML = foodMenu.reduce((html, food, index) => {
const {id, name, price, type} = food;
console.log(food);
return html + `<tr>
<td>${index + 1}</td>
<td>${name}</td>
<td>${price}</td>
<td>${type}</td>
</tr>`;
}, "");
};
const drinkMenuRender = ({drinkMenu}) => {
const tbody = document.querySelector("table#menu-drink tbody");
tbody.innerHTML = drinkMenu.reduce((html, drink, index) => {
const {id, name, price, adultOnly} = drink;
console.log(drink);
return html + `<tr>
<td>${index + 1}</td>
<td>${name}</td>
<td>${price}</td>
<td><input type='checkbox' onclick='return false;' ${adultOnly ? 'checked' : ''}/></td>
</tr>`;
}, "");
};
class Menu {
constructor(id, name, price){
this.id = id;
this.name = name;
this.price = price;
}
toString(){
return `id = ${this.id}, name = ${this.name}, price = ${this.price}`;
}
}
class Food extends Menu {
constructor(id, name, price, type){
super(id, name, price);
this.type = type;
}
toString(){
return `${super.toString()}, type = ${this.type}`;
}
}
class Drink extends Menu {
constructor(id, name, price, adultOnly){
super(id, name, price);
this.adultOnly = adultOnly;
}
toString(){
return `${super.toString()}, adultOnly = ${this.adultOnly}`;
}
}
/**
* 다음 데이터를 처리하기 위한 class를 작성하세요
* (Food와 Drink의 부모클래스 Menu 설계할 것)
*
* Food - id:string, name:string, price:number, type:string
* Drink - id:string, name:string, price:number, adultOnly:boolean
*/
const menuData = {
foodMenu : [
new Food('food101','잡채밥', 8000, '밥'),
new Food('food102','김치찌게', 7500, '밥'),
new Food('food103','로제파스타', 9000, '면'),
new Food('food104','돌솥비빔밥', 8000, '밥'),
new Food('food105','짬뽕', 9000, '면'),
],
drinkMenu : [
new Drink('drink201','생수', 1000, false),
new Drink('drink202','오렌지쥬스', 2500, false),
new Drink('drink203','사이다', 2000, false),
new Drink('drink204','생맥주 500cc', 4000, true),
new Drink('drink205','소주', 4000, true),
]
};
</script>
</body>
</html>