๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐Ÿš€ ์ž๋ฐ” ์Šคํฌ๋ฆฝํŠธ JavaScript

์ž๋ฐ” ์Šคํฌ๋ฆฝํŠธ ์ดˆ๊ธ‰ ๋ฌธ์ œ/ํ’€์ด ๐Ÿ“3๏ธโƒฃ

by Meteora_ 2021. 3. 3.
728x90

์กฐ๊ฑด - 'Script๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ฌธ์ œ๋ฅผ ํ’€์–ด๋ด…์‹œ๋‹ค.'

 

1.

์ฝ”๋“œ ํŽผ์น˜๊ธฐ->

๋”๋ณด๊ธฐ
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body id="bodycolor" style="background-color: "" ">

<h1>๋ฐฐ๊ฒฝ์ƒ‰์˜ ๋ณ€๊ฒฝ</h1>
๋‹ค์Œ ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๋ฉด ํ™ˆํŽ˜์ด์ง€์˜ ๋ฐฐ๊ฒฝ์ƒ‰์„ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
<br><br>
<button type="button" id="red" onclick="changecolor(1)">๋นจ๊ฐ•</button>
<button type="button" id="green" onclick="changecolor(2)">๋…น์ƒ‰</button>
<button type="button" id="blue" onclick="changecolor(3)">์ฒญ์ƒ‰</button>
<button type="button" id="orange" onclick="changecolor(4)">์ฃผํ™ฉ์ƒ‰</button>
<button type="button" id="black" onclick="changecolor(5)">๊ฒ€์ •์ƒ‰</button>
<button type="button" id="white" onclick="changecolor(6)">ํฐ์ƒ‰</button>

<script type="text/javascript">

let obj = document.getElementById("bodycolor");

function changecolor(num){
	
	if(num == 1){
		obj.style.backgroundColor="red";
	}
	if(num == 2){
		obj.style.backgroundColor="green";
	}
	if(num == 3){
		obj.style.backgroundColor="blue";
	}
	if(num == 4){
		obj.style.backgroundColor="orange";
	}
	if(num == 5){
		obj.style.backgroundColor="black";
	}
	if(num == 6){
		obj.style.backgroundColor="white";
	}
	
	
}


</script>

</body>
</html>

2.

์ฝ”๋“œ ํŽผ์น˜๊ธฐ->

๋”๋ณด๊ธฐ
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>

<h1>ํ™˜์˜ํ•ฉ๋‹ˆ๋‹ค</h1>
<br>
โ€ปํ˜„์žฌ์‹œ๊ฐ์€<input type="text" id="timemonitor" value="ํ˜„์žฌ์‹œ๊ฐ„">์ž…๋‹ˆ๋‹ค.

<script type="text/javascript">


let datetime = new Date();


alert(datetime.getHours()+":"+datetime.getMinutes()+":"+datetime.getSeconds()); //ํ™•์ธ์šฉ


let wholetime = datetime.getHours()+":"+datetime.getMinutes()+":"+datetime.getSeconds(); //์‹œ๋ถ„์ดˆ

document.getElementById("timemonitor").value=wholetime;




</script>

</body>



</html>

3.

์ฝ”๋“œ ํŽผ์น˜๊ธฐ->

๋”๋ณด๊ธฐ
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>

<h1>(๋ฌธ์ œ)</h1>
์˜์–ด ์†๋‹ด์œผ๋กœ "1์ผ 1๊ฐœ์”ฉ ๋จน์œผ๋ฉด ์˜์‚ฌ ํ•„์š”์—†๋‹ค"๋ผ๊ณ  ํ•˜๋Š” ๊ณผ์ผ์€ ๋ฌด์—‡์ผ๊นŒ์š”?
<br><br>
<input type="checkbox" id="answerlow">์˜์–ด(์†Œ๋ฌธ์ž)๋กœ ๋‹ตํ•œ๋‹ค
<br><br>
๋‹ต : <input type="text" id="answerzone">
<br><br>
<button type="button" id="confirm" onclick="confmethod()">๋‹ต์„์ฒตํฌ</button>

<script>


function confmethod() {
let low = document.getElementById('answerlow').checked;
let answer = document.getElementById('answerzone').value;

if(low == true){
if(answer == "apple" || answer == "APPLE" || answer == 'Apple'){
alert('์ •๋‹ต์ž…๋‹ˆ๋‹ค');
}else{
alert('์˜ค๋‹ต์ž…๋‹ˆ๋‹ค');
}
}else{
if(answer == '์‚ฌ๊ณผ' || answer == '๋Šฅ๊ธˆ'){
alert('์ •๋‹ต์ž…๋‹ˆ๋‹ค');
}else{
alert('์˜ค๋‹ต์ž…๋‹ˆ๋‹ค');
}
}
}
</script>


</body>
</html>

4.

์ฝ”๋“œ ํŽผ์น˜๊ธฐ ->

๋”๋ณด๊ธฐ
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>

<h1>๋ฏธ์ˆ ๊ด€ ๋ฐ ๋ฐ•๋ฌผ๊ด€์˜ ๋งํฌ</h1>

<form name="f1">
<select name="locationname" onchange="golink()">

<option>-๋Œ€์ƒ์„ ์„ ํƒ</option>
<option value="http://sema.seoul.go.kr">-์„œ์šธ์‹œ๋ฆฝ๋ฏธ์ˆ ๊ด€</option>
<option value="http://www.mmca.go.kr">-๊ตญ๋ฆฝํ˜„๋Œ€๋ฏธ์ˆ ๊ด€</option>
<option value="http://www.sac.or.kr">-์˜ˆ์ˆ ์˜์ „๋‹น</option>
<option value="http://www.museum.go.kr">-๊ตญ๋ฆฝ์ค‘์•™๋ฐ•๋ฌผ๊ด€</option>
<option value="http://www.museum.seoul.kr">-์„œ์šธ์—ญ์‚ฌ๋ฐ•๋ฌผ๊ด€</option>
<option value="http://www.nfm.go.kr">-๊ตญ๋ฆฝ๋ฏผ์†๋ฐ•๋ฌผ๊ด€</option>

</select>
</form>

<script type="text/javascript">

function golink(){
	
	let n= document.f1.locationname.selectedIndex;
	
	if(n!=0){
		location.href=document.f1.locationname.options[n].value;
	}
	
}

</script>

</body>
</html>

5.

์ฝ”๋“œ ํŽผ์น˜๊ธฐ ->

 

๋”๋ณด๊ธฐ
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>

<h1>2๊ฐœ์˜ ์ฃผ์‚ฌ์œ„</h1>
๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๋ฉด 2๊ฐœ์˜ ์ฃผ์‚ฌ์œ„๊ฐ€ ๋žœ๋ค์œผ๋กœ ๋‚˜์˜จ๋‹ค.<br><br>
<table>
<tr>
	<td style="padding-right: 15px;"><img alt="" src="sai_1.gif"> </td>
	<td><img alt="" src="sai_6.gif"> </td>
</tr>
</table>
<br>
<button type="button" onclick="randomDice()">์ฃผ์‚ฌ์œ„ ๊ตด๋ฆผ.</button>


<script type="text/javascript">
	var diceNum = 1;
	var diceNum2 = 6;
	var count = 5;
	var time = 0;
	
	
function throwDice() {
	count = count - 1; 
	
	if(count != 0) { 
		
		diceNum = diceNum+1;
		if(diceNum == 7) {
			diceNum = 1;
		}
		var imgsrc = document.getElementsByTagName("img")[0];
		var str = "sai_"+diceNum+".gif";
		imgsrc.src = str;
		
	
		diceNum2 = diceNum2 - 1;
		if(diceNum2 == 0) {
			diceNum2 = 6;
		}
		var imgsrc2 = document.getElementsByTagName("img")[1];
		var str2 = "sai_"+diceNum2+".gif";
		imgsrc2.src = str2;
	}
	else if(count==0){
		
		clearInterval(time);
		
		var num = Math.floor(Math.random()*6)+1;
		var num2 = Math.floor(Math.random()*6)+1;

		var imgsrc = document.getElementsByTagName("img")[0];
		var str = "sai_"+num+".gif";
		imgsrc.src = str;
		
	
		var imgsrc2 = document.getElementsByTagName("img")[1];
		var str2 = "sai_"+num2+".gif";
		imgsrc2.src = str2;
		
		
	}
	
}
function randomDice() {
	count = 10;
	clearInterval(time);
	time = setInterval("throwDice()",50);
	
}



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

6.

์ฝ”๋“œ ํŽผ์น˜๊ธฐ->

๋”๋ณด๊ธฐ
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	
	<h1>๋‹ค์Œ ์ƒ์ผ๊นŒ์ง€ ๋‚จ์€ ์ผ์ˆ˜</h1>
	<br>
	<pre>
	๋‹ค์Œ ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜์—ฌ ์ƒ์ผ์„ ์ž…๋ ฅํ•˜๋ฉด,
 	๋‹ค์Œ ์ƒ์ผ๊นŒ์ง€ ๋‚จ์€ ์ผ์ˆ˜๋ฅผ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
 	</pre>
	<button id="pushbutton" onclick="calbirth()">์ƒ์ผ์„ ์ž…๋ ฅ</button>
	<input type="text" id="ide">
	
	<script>
	
	function calbirth(){
		
		let birthMonth = prompt("๋ช‡์›”์ธ๊ฐ€์š”? 1 ~ 12","");
		let birthDate = prompt("๋ช‡์ผ ์ธ๊ฐ€์š”? 1~31","")
		
		
		let now = new Date();
		let birthday = new Date(birthMonth+"/"+birthDate+"/"+now.getFullYear());
		
		
		birthday.setMonth(birthMonth-1);
		birthday.setDate(birthDate);
		
		let monthSec = birthday.getTime() - now.getTime();
		
		if(monthSec <= 0){
			birthday.setFullYear(now.getFullYear()+1);
			monthSec = birthday.getTime() - now.getTime();
		}
		
		let days = monthSec / (24 * 60 * 60 * 1000)
		
		days = Math.ceil(days);
		
		alert("๋‹ค์Œ ์ƒ์ผ๊นŒ์ง€" + days + "์ผ ๋‚จ์Œ");
		
	}

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

 

๋” ์ข‹์€ ์ฝ”๋“œ๊ฐ€ ์žˆ๋‹ค๋ฉด confirm ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค. 

 

๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.

๋Œ“๊ธ€