[JS] ๊ธฐ๋ณธ์—ฐ์‚ฐ์ž ์—ฐ์Šต๋ฌธ์ œ 1, 2

2021. 10. 25. 23:09ใ†HTML + CSS + JS/JS ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ

728x90

* ์—ฐ์Šต๋ฌธ์ œ 1

<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title> ์ข…ํ•ฉ์‹ค์Šต1-1 </title>
<script>
	var price1 = 3000;
	var price2 = 6000;
	var price3 = 3000;

	var total = price1 + price2 + price3; 

	var result = (total > 10000) ? (total-10000) + "์› ์ดˆ๊ณผ!" : "๋ˆ ๊ด€๋ฆฌ๋ฅผ ์ž˜ ํ–ˆ์–ด์š”!";
	document.write(result);

</script>
</head>
<body>
</body>
</html>

 

 

* ์—ฐ์Šต๋ฌธ์ œ 2

<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title> ์ข…ํ•ฉ์‹ค์Šต1-2 </title>
<script>
		var avgSales = (1200 + 1300 + 1000)/ 3; //ํ‰๊ท  ํŒ๋งค๋Ÿ‰ 
		var fourth = prompt("4๋ถ„๊ธฐ ํŒ๋งค๋Ÿ‰์€?", "0");
		var msg_1 = "ํŒ๋งค๋Ÿ‰์ด ํ‰๊ท  ์ด์ƒ์ž…๋‹ˆ๋‹ค.",
						msg_2 = "ํˆ๋งค๋Ÿ‰์ด ํ‰๊ท  ๋ฏธ๋‹ฌ์ž…๋‹ˆ๋‹ค.";
		
		var result =  (fourth > avgSales) ? "ํŒ๋งค๋Ÿ‰์ด ํ‰๊ท  ์ด์ƒ์ž…๋‹ˆ๋‹ค." : "ํŒ๋งค๋Ÿ‰์ด ํ‰๊ท  ๋ฏธ๋‹ฌ์ž…๋‹ˆ๋‹ค.";
		document.write(result);
</script>
</head>
<body>
</body>
</html>
728x90