javascript 연습

In this example below you will see how to do a javascript 연습 with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by 2ju2, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright 2ju2 ©
  • HTML
  • CSS
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>javascript 연습</title>
  
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css">

  
      <link rel="stylesheet" href="css/style.css">

  
</head>

<body>

  

<div class="bottom_line">
  <div class="bold">중첩조건문</div>
  <div class="prac_5" id="prac_5">

  </div>
</div>

<div class="bottom_line">
  <div class="bold">Date 객체 메서드</div>
  <div class="prac_4" id="prac_4">

  </div>
</div>

<div class="bottom_line">
  <div class="bold">복합대입 연산자의 활용</div>
  <div class="prac_3" id="prac_3">

  </div>
</div>

<div class="bottom_line">
  <div class="bold">증감연산자</div>
  <div id="prac_2">
    <p id="original"><p>
    <p id="plus"><p>
    <p id="minus"><p>
  </div>
</div>

<div class="bottom_line">
  <div class="bold">재선언오류
  <div id="prac_3">

  </div>
</div>
  
  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/2ju2/javascript-andxc5f0andxc2b5-NpzRMj */
.bottom_line{;border-bottom:solid 1px #333; margin-bottom:20px; padding-bottom:20px;}
.bold{font-weight:700; font-size:large; margin-bottom:10px;}

p, li, span{line-height:1.3em;}

/*Downloaded from https://www.codeseek.co/2ju2/javascript-andxc5f0andxc2b5-NpzRMj */
//alert("동해물과 백두산이\t마르고 닳도록");

//복합대입 연산자의 활용

window.onload = function(){
  
  var list = '';
  list += '<ul>';
  list +=   '<li>1번째 li</li>';
  list +=   '<li>2번째 li</li>';
  list += '</ul>';

  //document.body.innerHTML = list;
  //document.getElementById('prac_1').innerHTML = list;
  document.getElementsByClassName('prac_1')[0].innerHTML = list;
  
};
 
//증감연산자
var num_2 = 10;

//document.getElementById('prac_2').innerHTML = num_2;
document.getElementById('original').innerHTML = num_2;
num_2++;
num_2++;
document.getElementById('plus').innerHTML = num_2;
num_2--;
num_2--;
document.getElementById('minus').innerHTML = num_2;

//재선언 오류
var alert = 'red Alert';
//alert(alert);
//console.log(alert);

//자료형검사
console.log(typeof ("문자"));
console.log(typeof (123));
console.log(typeof (true));
console.log(typeof (function(){})); // 함수
console.log(typeof ({})); //객체
console.log(typeof(alpha));

//var Input = prompt('숫자를입력해주세요', '숫자');
//var numberInput = Number(Input);
//alert(typeof (input));
//alert(typeof (numberInput) + ': ' + numberInput);

//date 객체 메서드


  
  var date = new Date();
  var GDate = date.getDate();
  var GMonth = date.getMonth()+1;
  var GSeason;

  if(GMonth >= 3 && GMonth <= 5){
    var GSeason = '봄';
  }else{
    var GSeason = '겨울';
  }

  var text4 = '';
  text4 += '<dl>';
  text4 +=  '<dt style="font-weight:700">default</dt>'
  text4 +=    '<dd>';
  text4 +=      date
  text4 +=    '</dd>';
  text4 +=  '<dt style="font-weight:700">date</dt>'
  text4 +=    '<dd>';
  text4 +=      GDate;
  text4 +=    '</dd>';
  text4 +=  '<dt style="font-weight:700">month</dt>'
  text4 +=    '<dd>';
  text4 +=      '지금은' + GMonth + '월 입니다.';
  text4 +=    '</dd>';
  text4 += '</dl>';
  text4 +=  '<dt style="font-weight:700">season</dt>'
  text4 +=    '<dd>';
  text4 +=      '지금 계절은 ' + GSeason + '입니다.';
  text4 +=    '</dd>';
  text4 += '</dl>';
  

  document.getElementById('prac_4').innerHTML = text4;
  

//중첩조건문

var date = new Date();
var hour = date.getHours();
var eat = '';

if(hour < 11){
  var eat = '아침 먹을 시간입니다.'
}else{
  if(hour < 13){
    var eat = '점심 먹을 시간입니다.'
  }else{
    var eat = '저녁 먹을 시간입니다.'
  }
}

document.getElementById('prac_5').innerHTML = eat;

//논리연산자와 조건문
//var score = Number(prompt('학점을 입력하세요.', '4.4'));

	//for 반복문의 특이한 사용
	/* var startTime = new Date().getTime();
	for (var CPS = 0; new Date().getTime() > startTime + 1000; CPS++ )
	{
		alert("초 당 연산 횟수: " + CPS);
	} */

//중첩반복문

	/*
	1-1 : output = *
	1-2 : output = *\n
	2-1 : output = *\n**
	2-2 : output = *\n**\n
	3-1 : output = *\n**\n***
	3-2 : output = *\n**\n***\n

	*/

/* 
	var output = "";
	for(var i=0; i<10; i++){
		output += '*';
	}for (var j=1; j<10 ; j)
	{
		output += '\n';
	}

	alert(output); 
 */
var output="";
for(var i=0; i<10; i++){
 
  output +="*";
}

alert(output);

Comments