2021-01-14 HTML問題1-10


<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>실습 10번</title>

<script>
	function CreateBook(bookName, writer, pay) {
		var book = new Object();

		book.bookName = bookName;
		book.writer = writer;
		book.pay = pay;

		bookArray.push(book);
	}

	function SearchBigBookPay() {
		var bigBookPay = bookArray[0].pay;

		for (var i = 0; i < bookArray.length; i++) {
			if (bigBookPay < bookArray[i].pay) {
				bigBookPay = bookArray[i].pay;
			}
		}
		for (var i = 0; i < bookArray.length; i++) {
			if (bigBookPay == bookArray[i].pay) {
				bigBook = bookArray[i].bookName;
			}
		}
	}
</script>

</head>
<body>
	<script>
		var bookArray = [];
		var bigBook;

		while (true) {
			var input = prompt("콤마로 분리하면서 책 제목 저자 가격 순으로 입력 " + bookArray.length + "번 입력되었습니다.");
			if (input == 0) {
				break;
			}

			var arrArray = input.split(",");
			if(arrArray.length != 3){
				document.write("책이름, 저자, 가격 을 입력해주세요");
			}
			else{
				CreateBook(arrArray[0], arrArray[1], arrArray[2]);
			}
		}

		SearchBigBookPay();

		document.write("가장 가격이 비싼 책은 " + bigBook + " 입니다.");
	</script>
</body>
</html>