๐Ÿ”2022-08-04๐Ÿ”

 

ex7-01.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>๊ฐ์ฒด ์ƒ์„ฑ ๋ฐ ํ™œ์šฉ</title>
</head>
<body>
<h3>๊ฐ์ฒด ์ƒ์„ฑ ๋ฐ ํ™œ์šฉ</h3>
<hr>
<script>
	// Date ๊ฐ์ฒด ์ƒ์„ฑ
	let today = new Date();

	// Date ๊ฐ์ฒด์˜ toLocaleString() ๋ฉ”์†Œ๋“œ ํ˜ธ์ถœ
	document.write("ํ˜„์žฌ ์‹œ๊ฐ„ : " + today.toLocaleString() + "<br>");

	// String ๊ฐ์ฒด ์ƒ์„ฑ
	let mystr= new String("์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ๊ณต๋ถ€ํ•˜๊ธฐ");
	document.write("mystr์˜ ๋‚ด์šฉ : " + mystr + "<br>");
	document.write("mystr์˜ ๊ธธ์ด : " + mystr.length + "<br>");
	// mystr.length=10; // ์ด ๋ฌธ์žฅ์€ ์˜ค๋ฅ˜์ด๋‹ค.
</script>
</body>
</html>

 

ex7-02.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>[]๋กœ ๋ฐฐ์—ด ๋งŒ๋“ค๊ธฐ</title>
</head>
<body>
<h3>[]๋กœ ๋ฐฐ์—ด ๋งŒ๋“ค๊ธฐ</h3>
<hr>
<script>
	let plots = [20, 5, 8, 15, 20]; // ์›์†Œ 5๊ฐœ์˜ ๋ฐฐ์—ด ์ƒ์„ฑ
	document.write("var plots = [20, 5, 8, 15, 20]<br>");

	for(let i=0; i<5; i++) { // 5 ๋Œ€์‹  plots.length๋กœ ํ•ด๋„ ๋จ
		let size = plots[i]; // plots ๋ฐฐ์—ด์˜ i๋ฒˆ์งธ ์›์†Œ
		while(size>0) {
			document.write("*");
			size--;
		}
		document.write(plots[i] + "<br>");
	}
</script>
</body>
</html>

 

ex7-03.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Array ๊ฐ์ฒด๋กœ ๋ฐฐ์—ด ๋งŒ๋“ค๊ธฐ</title>
</head>
<body>
<h3>Array ๊ฐ์ฒด๋กœ ๋ฐฐ์—ด ๋งŒ๋“ค๊ธฐ</h3>
<hr>
<script>
	let degrees = new Array(); // ๋นˆ ๋ฐฐ์—ด ์ƒ์„ฑ
	degrees[0] = 15.1;
	degrees[1] = 15.4;
	degrees[2] = 16.1;
	degrees[3] = 17.5;
	degrees[4] = 19.2;
	degrees[5] = 21.4;

	let sum = 0;
	// for(let i=0; i<degrees.length; i++)
	// 	sum += degrees[i];
	for(let i of degrees){
		sum += i;
	}

	document.write("ํ‰๊ท  ์˜จ๋„๋Š” " + sum/degrees.length + "<br>");
</script>
</body>
</html>

 

ex7-04.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>[]๋กœ ๋ฐฐ์—ด ๋งŒ๋“ค๊ธฐ</title>
</head>
<body>
<h3>[]๋กœ ๋ฐฐ์—ด ๋งŒ๋“ค๊ธฐ</h3>
<hr>
<script>
	let plots = [20, 5, 8, 15, 20]; // ์›์†Œ 5๊ฐœ์˜ ๋ฐฐ์—ด ์ƒ์„ฑ
	document.write("var plots = [20, 5, 8, 15, 20]<br>");

	for(let i=0; i<5; i++) { // 5 ๋Œ€์‹  plots.length๋กœ ํ•ด๋„ ๋จ
		let size = plots[i]; // plots ๋ฐฐ์—ด์˜ i๋ฒˆ์งธ ์›์†Œ
		while(size>0) {
			document.write("*");
			size--;
		}
		document.write(plots[i] + "<br>");
	}
</script>
</body>
</html>

 

ex7-07.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>String ๊ฐ์ฒด์˜ ๋ฉ”์†Œ๋“œ ํ™œ์šฉ</title>
</head>
<body>
<h3>String ๊ฐ์ฒด์˜ ๋ฉ”์†Œ๋“œ ํ™œ์šฉ</h3>
<hr>
<script>
	let a = new String("Boys and Girls");
	let b = "!!";
	document.write("a : " + a + "<br>");
	document.write("b : " + b + "<br><hr>");

	document.write(a.charAt(0) + "<br>");
	document.write(a.concat(b, "์ž…๋‹ˆ๋‹ค") + "<br>");
	document.write(a.indexOf("s") + "<br>");
	document.write(a.indexOf("And") + "<br>");
	document.write(a.slice(5, 8) + "<br>");
	document.write(a.substr(5, 3) + "<br>");
	document.write(a.toUpperCase() + "<br>");
	document.write(a.replace("and", "or") + "<br>");
	document.write("   kitae   ".trim() + "<br><hr>");

	let sub = a.split(" ");
	document.write("a๋ฅผ ๋นˆ์นธ์œผ๋กœ ๋ถ„๋ฆฌ<br>");
	for(let i=0; i<sub.length; i++)
		document.write("sub" + i + "=" + sub[i] + "<br>");

	document.write("<hr>String ๋ฉ”์†Œ๋“œ๋ฅผ ์‹คํ–‰ ํ›„ a์™€ b ๋ณ€ํ•จ ์—†์Œ<br>");
	document.write("a : " + a + "<br>");
	document.write("b : " + b + "<br>");
</script>
</body>
</html>

 

ex7-10.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>๋ฆฌํ„ฐ๋Ÿด ํ‘œ๊ธฐ๋ฒ•์œผ๋กœ ๊ฐ์ฒด ๋งŒ๋“ค๊ธฐ</title>
<script>
	//์‚ฌ์šฉ์ž ๊ฐ์ฒด ๋งŒ๋“ค๊ธฐ
	let account = {
		// ํ”„๋กœํผํ‹ฐ ์ƒ์„ฑ ๋ฐ ์ดˆ๊ธฐํ™”
		owner : "ํ™ฉ๊ธฐํƒœ", // ๊ณ„์ขŒ ์ฃผ์ธ
		code : "111", // ๊ณ„์ขŒ ์ฝ”๋“œ
		balance : 35000, // ์ž”์•ก ํ”„๋กœํผํ‹ฐ

		// ๋ฉ”์†Œ๋“œ ์ž‘์„ฑ
		inquiry : function () { return this.balance; }, // ์ž”๊ธˆ ์กฐํšŒ
		deposit : function(money) { this.balance += money; }, // ์ €๊ธˆ. money ๋งŒํผ ์ €๊ธˆ
		withdraw : function (money) { // ์˜ˆ๊ธˆ ์ธ์ถœ, money๋Š” ์ธ์ถœํ•˜๊ณ ์ž ํ•˜๋Š” ์•ก์ˆ˜
			// money๊ฐ€ balance๋ณด๋‹ค ์ž‘๋‹ค๊ณ  ๊ฐ€์ •
			this.balance -= money;
			return money;
		}
	};
</script>
</head>
<body>
<h3>๋ฆฌํ„ฐ๋Ÿด ํ‘œ๊ธฐ๋ฒ•์œผ๋กœ ์‚ฌ์šฉ์ž ๊ฐ์ฒด ๋งŒ๋“ค๊ธฐ</h3>
<hr>
<script>
	document.write("account : ");
	document.write(account.owner + ", ");
	document.write(account.code + ", ");
	document.write(account.balance + "<br>");

	account.deposit(10000); // 10000์› ์ €๊ธˆ
	document.write("10000์› ์ €๊ธˆ ํ›„ ์ž”์•ก์€ " + account.inquiry() + "<br>");
	account.withdraw(5000); // 5000์› ์ธ์ถœ
	document.write("5000์› ์ธ์ถœ ํ›„ ์ž”์•ก์€ " + account.inquiry() + "<br>");
</script>
</body>
</html>

 

ex7-11.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>ํ”„๋กœํ† ํƒ€์ž…์œผ๋กœ ๊ฐ์ฒด ๋งŒ๋“ค๊ธฐ</title>
<script>
	// ํ”„๋กœํ† ํƒ€์ž… ๋งŒ๋“ค๊ธฐ : ์ƒ์„ฑ์ž ํ•จ์ˆ˜ ์ž‘์„ฑ
	function Account(owner, code, balance) {
		// ํ”„๋กœํผํ‹ฐ ๋งŒ๋“ค๊ธฐ
		this.owner = owner; 	// ๊ณ„์ขŒ ์ฃผ์ธ ํ”„๋กœํผํ‹ฐ ๋งŒ๋“ค๊ธฐ
		this.code = code; 		// ๊ณ„์ขŒ ์ฝ”๋“œ ํ”„๋กœํผํ‹ฐ ๋งŒ๋“ค๊ธฐ
		this.balance = balance; // ์ž”์•ก ํ”„๋กœํผํ‹ฐ ๋งŒ๋“ค๊ธฐ

		// ๋ฉ”์†Œ๋“œ ๋งŒ๋“ค๊ธฐ
		this.inquiry = function () { return this.balance; }
		this.deposit = function (money) { this.balance += money; }
		this.withdraw = function (money) { // ์˜ˆ๊ธˆ ์ธ์ถœ, money๋Š” ์ธ์ถœํ•˜๋Š” ์•ก์ˆ˜
			// money๊ฐ€ balance๋ณด๋‹ค ์ž‘๋‹ค๊ณ  ๊ฐ€์ •
			this.balance -= money;
			return money;
		}
	}
</script>
</head>
<body>
<h3>Account ํ”„๋กœํ† ํƒ€์ž… ๋งŒ๋“ค๊ธฐ</h3>
<hr>
<script>
	// new ์—ฐ์‚ฐ์ž ์ด์šฉํ•˜์—ฌ ๊ณ„์ขŒ ๊ฐ์ฒด ์ƒ์„ฑ
	let account = new Account("ํ™ฉ๊ธฐํƒœ", "111", 35000);

	// ๊ฐ์ฒด ํ™œ์šฉ
	document.write("account : ");
	document.write(account.owner + ", ");
	document.write(account.code + ", ");
	document.write(account.balance + "<br>");

	account.deposit(10000); // 10000์› ์ €๊ธˆ
	document.write("10000์› ์ €๊ธˆ ํ›„ ์ž”์•ก์€ " + account.inquiry() + "<br>");
	account.withdraw(5000); // 5000์› ์ธ์ถœ
	document.write("5000์› ์ธ์ถœ ํ›„ ์ž”์•ก์€ " + account.inquiry() + "<br>");
</script>
</body>
</html>

+ Recent posts