๐ŸŽจ ์‚ฌ๊ฐํ˜• ๋„ˆ๋น„ ๊ณ„์‚ฐ / ํ• ์ธ ๊ฐ€๊ฒฉ ๊ณ„์‚ฐ ํ”„๋กœ๊ทธ๋žจ

kirin.logยท2020๋…„ 11์›” 24์ผ
1

์‚ฌ๊ฐํ˜• ๋„“์ด ๊ณ„์‚ฐ

<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>์‚ฌ๊ฐํ˜• ๋„ˆ๋น„ ๊ตฌํ•˜๊ธฐ</title>
</head>
<body>	
<script>
	var width = prompt("๊ฐ€๋กœ ๊ธธ์ด๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”.");  //promp์ฐฝ์ด ๋–ด์„ ๋•Œ, ์‚ฌ์šฉ์ž๊ฐ€ ์ž…๋ ฅํ•œ ๊ฐ’์ด width ๊ฐ’์œผ๋กœ ์ง€์ •
	var height = prompt("์„ธ๋กœ ๊ธธ์ด๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”");  //promp์ฐฝ์ด ๋–ด์„ ๋•Œ, ์‚ฌ์šฉ์ž๊ฐ€ ์ž…๋ ฅํ•œ ๊ฐ’์ด width ๊ฐ’์œผ๋กœ ์ง€์ •
	var area = width * height;  //์‚ฌ์šฉ์ž๊ฐ€ ์ž…๋ ฅํ•œ ๊ฐ’๋“ค์˜ ๊ณฑ์ด area๊ฐ’์ด ๋จ
	alert("์‚ฌ๊ฐํ˜•์˜ ๋„“์ด๋Š” " + area + "์ž…๋‹ˆ๋‹ค");  //alert์ฐฝ์ด ๋œจ๋ฉด์„œ area๊ฐ’์ด ์ถœ๋ ฅ
</script>
</body>
</html>

ํ• ์ธ ๊ฐ€๊ฒฉ ๊ณ„์‚ฐ ํ”„๋กœ๊ทธ๋žจ

<!DOCTYPE html>
<html lang="ko">
<head>
   <meta charset="UTF-8">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <meta http-equiv="X-UA-Compatible" content="ie=edge">
   <title>ํ• ์ธ ๊ฐ€๊ฒฉ ๊ตฌํ•˜๊ธฐ</title>
</head>
<body>	
  <div id="contents">
     <ul>
	<li>
	   <label for="oPrice">์›๋ž˜ ๊ฐ€๊ฒฉ</label>  <!--label์˜ for๊ฐ’(oPrice)๊ณผ input์˜ id๊ฐ’(oPrice)์„ ๊ฐ™๊ฒŒ ์—ฐ๊ฒฐํ•ด์•ผ ํ•œ๋‹ค-->
	   <input type="text" id="oPrice">์›
	</li>
	<li>
	   <label for="rate">ํ• ์ธ์œจ</label>
	   <input type="text" id="rate">%
	</li>
	<li>
	   <button onclick="showPrice()">ํ• ์ธ ๊ฐ€๊ฒฉ ๊ณ„์‚ฐํ•˜๊ธฐ</button>
	</li>
     </ul>
     <div id="showResult"></div>  <!--'ํ• ์ธ๊ฐ€๊ฒฉ ๊ณ„์‚ฐํ•˜๊ธฐ'๋ฒ„ํŠผ์„ ๋ˆ„๋ฅธ ํ›„ ๊ฒฐ๊ณผ๊ฐ’์ด ๋‚˜์˜ค๋Š” ๊ณต๊ฐ„ ๋งŒ๋“ค์–ด์ฃผ๊ธฐ-->	
  </div>	
<script>
   function showPrice(){
	var originPrice = document.querySelector('#oPrice').value;  //originPrice ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•œ ๋’ค, '์›๋ž˜๊ฐ€๊ฒฉ'๊ฐ’์„ ๋ถˆ๋Ÿฌ์˜ค๋„๋ก ์„ค์ •
	var rate = document.querySelector('#rate').value;  //rate ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•œ ๋’ค, 'ํ• ์ธ์œจ'๊ฐ’์„ ๋ถˆ๋Ÿฌ์˜ค๋„๋ก ์„ค์ •
	var savedPrice = originPrice * (rate / 100);  //savedPrice ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•œ ๋’ค, ํ• ์ธ์œจ์„ ๊ณ„์‚ฐํ•˜๋Š” ๊ณต์‹ ์„ค์ •(์œ„์— ์„ ์–ธํ•œ ๋ณ€์ˆ˜๊ฐ’๋“ค์„ ์ด์šฉํ•˜์—ฌ)
	var resultPrice = originPrice - savedPrice;
	document.querySelector('#showResult').innerHTML = 
  	    `${originPrice}์›์—์„œ ${rate}%๊ฐ€ ํ• ์ธ๋˜์–ด ${savedPrice}์› ์ €๋ ดํ•œ ${resultPrice}์›์— ๊ตฌ๋งคํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค`;
	}  //document๋กœ ์ถœ๋ ฅ(html ์•ˆ์˜ #showResult๊ฐ’์„ ์†Œํ™˜ํ•˜์—ฌ)
</script>
</body>
</html>

profile
boma91@gmail.com

0๊ฐœ์˜ ๋Œ“๊ธ€