[Day5] JS 5 [11/24] 

 

--๋ณต์Šต--

1. ๋กœ๋˜ ๋ฒˆํ˜ธ ๋ฐœ์ƒ๊ธฐ ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๋ฉด ๋กœ๋˜ ๋ฒˆํ˜ธ๊ฐ€ p ํƒœ๊ทธ์— ์ถœ๋ ฅ๋˜๋„๋ก js ์ฝ”๋”ฉ ํ•˜์„ธ์š”

 ( ์กฐ๊ฑด : ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌ ํ•ด์„œ ์ถœ๋ ฅ )

<button>๋กœ๋˜ ๋ฒˆํ˜ธ  ๋ฐœ์ƒ๊ธฐ</button>
<p id="demo"></p>
  $("button").click( function (){
	   // alert("1")
	  
	   // js  ๋ฐฐ์—ด ์„ ์–ธ
	   var lotto = [];
	   var n ;
	   while (  lotto.length < 6 ) {
		    n = getRndRange( 1, 45);
		     if(  isDuplicationLotto(lotto, n)  )     	lotto.push( n );
		    //lotto.push(n);
    	} // 
	   
    	lotto.sort( (a,b) => a-b );
    	
    	$("#demo").html( "<ul><li>" +  lotto.join("</li><li>")  +" </li></ul>");
    	
  });
  
  // 1.   min ~ max ๋ฐœ์ƒ์‹œํ‚ค๋Š” ํ•จ์ˆ˜
  function getRndRange( min, max){
	  return  Math.floor(  Math.random()*(max-min+1)  ) + min;
  }
  
  // 2. ์ค‘๋ณต ์ฒดํฌํ•˜๋Š” ํ•จ์ˆ˜
  function isDuplicationLotto( lotto, n ){
	  return lotto.every( (elt, i, array) =>  elt !=  n ) ;
	  /* 
	  return lotto.every(function(elt, i, array) {
	  	return elt != n ;
	  })
	   */
  }

2.

  ใ„ฑ. select ํƒœ๊ทธ์— 1์—์„œ 20๊นŒ์ง€์˜ option ํƒœ๊ทธ๋ฅผ js๋กœ ์ถ”๊ฐ€ํ•˜๊ณ 

  ใ„ด. ๋กœ๋˜ ๊ฒŒ์ž„ ํšŸ์ˆ˜๋ฅผ select ํƒœ๊ทธ์—์„œ ์„ ํƒ ํ›„ ๋กœ๋˜ ๋ฒˆํ˜ธ ์ถœ๋ ฅํ•˜๋Š” js ์ฝ”๋”ฉํ•˜์„ธ์š”.

<select id="cmbCnt"></select>
<br>
<button>๋กœ๋˜ ๋ฒˆํ˜ธ  ๋ฐœ์ƒ๊ธฐ</button>
<p id="demo"></p>
 <script>

   // 1.  select ์š”์†Œ์— options 20๊ฐœ ์ถ”๊ฐ€
   for (var i = 1; i <= 20; i++) {
	 $("#cmbCnt").append(   $("<option></option>").text( i ).val( i )    );
  }  // for
  
  /* [1์กฐ]
  var op = "";
  for (var i = 1; i <= 20; i++) {
      op += "<option value=" + i + ">" + i + "</option>";
  }
  // document.getElementById("cmbCnt").innerHTML = op;
  $("#cmbCnt").html( op );
  */
  
  // 2.  [jquery ajax ] - on(์ด๋ฒคํŠธ ๋“ฑ๋ก)
  $("button").on("click", function() {
	  // js ์ปฌ๋ ‰์…˜ ํด๋ž˜์Šค( list, set, map )
  	 var lottos = [];  // 2์ฐจ์› ๋ฐฐ์—ด
  	  
  	 // selected option์˜ value ์†์„ฑ
  	 var gCnt = $("#cmbCnt").val();
  	 // alert( gCnt );
  	 
  	 for (var i = 1; i <= gCnt; i++) {
	  	   var lotto = [];
	 	   var n ;
	 	   while (  lotto.length < 6 ) {
	 		    n = getRndRange( 1, 45);
	 		     if(  isDuplicationLotto(lotto, n)  )     	lotto.push( n );
	 		    //lotto.push(n);
	  	    } //  while
	  	   lotto.sort( (a,b) => a-b );
	  	    
	  	   lottos.push( lotto ); 
	 } // for
  	   
  	 $("#demo").html(  lottos.join("<br>").toString()  );
  });
  
  
  // [ lotto.js ์™ธ๋ถ€js ]
  // 1.   min ~ max ๋ฐœ์ƒ์‹œํ‚ค๋Š” ํ•จ์ˆ˜
  function getRndRange( min, max){
	  return  Math.floor(  Math.random()*(max-min+1)  ) + min;
  }
  
  // 2. ์ค‘๋ณต ์ฒดํฌํ•˜๋Š” ํ•จ์ˆ˜
  function isDuplicationLotto( lotto, n ){
	  return lotto.every( (elt, i, array) =>  elt !=  n ) ;
	  /* 
	  return lotto.every(function(elt, i, array) {
	  	return elt != n ;
	  })
	   */
  }
</script>

3. ๊ตฌ๊ตฌ๋‹จ ์ถœ๋ ฅ ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๋ฉด  p ํƒœ๊ทธ์— ํ…Œ์ด๋ธ” ํ˜•์‹์œผ๋กœ ๊ตฌ๊ตฌ๋‹จ ์ถœ๋ ฅํ•˜๋Š” js ์ฝ”๋”ฉํ•˜์„ธ์š” .

<button>๊ตฌ๊ตฌ๋‹จ ์ถœ๋ ฅ ๋ฒ„ํŠผ</button>
<p id="demo"></p>
   // ๊ตฌ๊ตฌ๋‹จ  ๊ฐ€๋กœ, ์„ธ๋กœ ์ถœ๋ ฅ
   var content = "<table border='1' width='100%''>";
   // 2๋‹จ 3๋‹จ ~ 9๋‹จ  th
   content += "<tr>";
   for (var i = 2; i <=9; i++) {
	  content += "<th>"+i+"๋‹จ</th>";
   }
   content += "</tr>";
   // 
   for (var i = 1; i <=9 ; i++) {
	   content += "<tr>";
	   for (var j = 2; j <= 9; j++) {
		   content += "<td>";
		   content +=  j + " * " + i + " = " + ( j*i );
		   content += "</td>";
	   } // for j
	   content += "</tr>";
   } // for i 
   content += "</table>";
   
   // js innerText == jquery text()
   // js innerHTML == jquery html()
   $("#demo").html(  content );


์ฃผ๋ฏผ๋ฒˆํ˜ธ ๋งŒ๋‚˜์ด

     // ์ฃผ๋ฏผ๋“ฑ๋ก๋ฒˆํ˜ธ -> ๋งŒ๋‚˜์ด .
     function getAge(  rrn ){
    	 // "890123-1700001"
    	 /*
    	 rrn.substr(from, length);
    	 rrn.substring(from, to)
    	 rrn.slice(from, to);
    	 */
    	 // 89
    	 var bYear =  getCentry(rrn) + parseInt(  rrn.substr( 0, 2 )  );
    	 // 01
    	 var bMonth = parseInt(  rrn.substring(2 ,  4) );
    	 // 23
    	 var bDate = parseInt(  rrn.slice(4 ,  6) );
    	 // 1
    	 // var bGender = rrn.slice( -7, -6)
    	 var bGender = rrn.substr( 7, 1 );
    	 console.log( bYear +" / " + bMonth + " /  " + bDate + " / " + bGender);
    	 
    	 
    	 // 2022 - 1989  ์˜ฌํ•ด๋…„๋„ - ์ƒ์ผ๋…„๋„
    	 var today = new Date();
    	 var todayYear = today.getFullYear();
    	 var age = todayYear - bYear;    	 
    	 // ์˜ค๋Š˜ ์ƒ์ผ ์ง€๋‚ฌ์ง€ ์•Š์•˜์œผ๋ฉด   -1 
    	 //  js ๋‚ ์งœ  > ๋‚ ์งœ
    	 //  js ๋‚ ์งœ  < ๋‚ ์งœ    ๋น„๊ต์—ฐ์‚ฐ์ž
    	 //  js ๋‚ ์งœ  == ๋‚ ์งœ    ๋น„๊ต์—ฐ์‚ฐ์ž
    	 var birthday = new Date( todayYear, bMonth-1, bDate);
    	 today.setHours(0);
    	 today.setMinutes(0);
    	 today.setSeconds(0);
    	 today.setMilliseconds(0);
    	 
    	 if(  today  < birthday )  age--;
    	 
    	 console.log( birthday.toLocaleString() ) ;
    	 console.log( today.toLocaleString() ) ;
    	 
    	 return age;
     }
     
     
    function getCentry(  rrn ){
    	 var gender = rrn.substr( 7, 1 );    	 
    	 // 1,2,5,6    1900
    	 // 3,4,7,8   2000
    	 // 9,0         1800    	 
    	 if(  [1,2,5,6].some((elt, i, array) =>  elt == gender )     )   return 1900;
    	 else if(  [3,4,7,8].some((elt, i, array) =>  elt == gender )     )   return 2000;
    	 else return 1800;
    	 
    }

    // ๋งŒ๋‚˜์ด ์ƒ์ผ ์ง€๋‚œ   ์ƒํƒœ : 33
    //                          X ์ƒํƒœ : 32
     console.log( "> ๋งŒ ๋‚˜์ด :  " +   getAge("891125-1700001") );

๋‹ฌ๋ ฅ( ์ผ์ •๊ด€๋ฆฌ )

<style>
select {
	width: 100px;
	text-align: center;
}

* {
	box-sizing: border-box;
}

ul {
	list-style-type: none;
}

body {
	font-family: Verdana, sans-serif;
}

.month {
	padding: 70px 25px;
	width: 100%;
	background: #1abc9c;
	text-align: center;
}

.month ul {
	margin: 0;
	padding: 0;
}

.month ul li {
	color: white;
	font-size: 20px;
	text-transform: uppercase;
	letter-spacing: 3px;
}

.month .prev {
	float: left;
	padding-top: 10px;
}

.month .next {
	float: right;
	padding-top: 10px;
}

.weekdays {
	margin: 0;
	padding: 10px 0;
	background-color: #ddd;
}

.weekdays li {
	display: inline-block;
	width: 13.6%;
	color: #666;
	text-align: center;
}

.days {
	padding: 10px 0;
	background: #eee;
	margin: 0;
}

.days li {
	list-style-type: none;
	display: inline-block;
	width: 13.6%;
	text-align: center;
	margin-bottom: 5px;
	font-size: 12px;
	color: #777;
}

.days li .active {
	padding: 5px;
	background: #1abc9c;
	color: white !important
}
</style>
<h3>ex03.html - ๋‹ฌ๋ ฅ( ์ผ์ •๊ด€๋ฆฌ )</h3>
    
    <select id="cmbyear" onchange="changeDate()"></select>
    <select id="cmbmonth" onchange="changeDate()"></select>
    <select id="cmbdate"></select>
    
	<br>
	<br>
	<div class="month">
		<ul>
			<li class="prev" onclick="changeCalendar(-1)">&#10094;</li>
			<li class="next" onclick="changeCalendar(1)">&#10095;</li>
			<li>
			     <span id="month">August</span><br> 
			     <span id="year"	style="font-size: 18px">2017</span>
			</li>
		</ul>
	</div>
	<ul class="weekdays">
		<li>Su</li>
		<li>Mo</li>
		<li>Tu</li>
		<li>We</li>
		<li>Th</li>
		<li>Fr</li>
		<li>Sa</li>
	</ul>
	<ul class="days">
    </ul>
    var today = new Date();
    var tYear = today.getFullYear();
    var tMonth = today.getMonth();
    // select 1970~2050 ๋…„๋„ option ์ถ”๊ฐ€.
    // js
    // jquery
    for (var i = 1970; i <= 2050; i++) {
    	$("#cmbyear").append( $("<option></option").text( i ) );
	}
    // ํ˜„์žฌ ๋…„๋„๋กœ option ์„ ํƒ
    $("#cmbyear").val(  tYear );
     
    
    // select 1~12 ์›” option ์ถ”๊ฐ€.
    // js
    // jquery
    for (var i = 1; i <= 12; i++) {
    	$("#cmbmonth").append( $("<option></option").text( i ) );
	}
    // ํ˜„์žฌ ์›”๋กœ option ์„ ํƒ
    $("#cmbmonth").val(  tMonth + 1 ); 
////////////////////////////////////////////////////////////////////////////////////
      // select year, month ์˜ต์…˜์„ ์„ ํƒํ•  ๋•Œ .. change ์ด๋ฒคํŠธ ํ˜ธ์ถœ๋˜๋Š” ํ•จ์ˆ˜( ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ )
      function changeDate(){
    	  year =  $("#cmbyear").val(  );
    	  month = $("#cmbmonth").val(  );
    	  console.log( year + " /  " + month );
    	  
    	  var lastDay = getLastDay(year, month);
    	  
    	  $("#cmbdate").html(""); // ์ดˆ๊ธฐํ™”  
    	  for (var i = 1; i <= lastDay; i++) {
    		  $("#cmbdate").append( $("<option></option").text( i ) );
		  } // for
		  
    	  // 
    	  printCalendar(year, month);
      }
      
      function printCalendar(year, month){
    	  //  <span id="month">August</span><br> 
		  //  <span id="year"	style="font-size: 18px">2017</span>
		  $("#month").text(  month  );
		  $("#year").text(  year  );
		  
		  //  <li>1</li> ~ <li>28,29,30,31</li>   append()
    	  // 1.    year, month, 1  ๋ฌด์Šจ ์š”์ผ ? 
    	  var dayOfWeek = getDayOfWeek( year, month, 1 );		  
    	  // 2. ๋งˆ์ง€๋ง‰ ๋‚ ์งœ
    	  var lastDay = getLastDay(year, month);
    	  
    	  
    	  // <ul class="days">
    	  $("ul.days").html("");  // ์ดˆ๊ธฐํ™”
          //๋นˆ๊ฑฐ ๋„ฃ๋Š” ์ž‘์—…
    	  for (var i = 0; i < dayOfWeek ; i++) {
    		  $("ul.days").append($("<li></li>"));
		  } // for
		  // 1~๋งˆ์ง€๋ง‰๋‚ ์งœ.
		  
		  var outputDay ;  // ์ถœ๋ ฅ ๋‚ ์งœ.
		  var toDay = new Date();  // ์˜ค๋Š˜ ๋‚ ์งœ
		  
		  for (var i = 1; i <= lastDay ; i++) {    		  
    		  // if( ์ถœ๋ ฅ๋‚ ์งœ == ์˜ค๋Š˜๋‚ ์งœ)  active ํด๋ž˜์Šค ์†์„ฑ ์ถ”๊ฐ€
    		  outputDay =new Date( year, month-1 , i );    		  
    		  //console.log( outputDay.toDateString() +" / " + toDay.toDateString()
    		  //	  + " / " + (toDay.toDateString() == outputDay.toDateString() ))
    		  
    		  if(  toDay.toDateString() == outputDay.toDateString() ){
    			  // <li><span class="active">10</span></li>
    			  $("ul.days").append(  "<li><span class='active'>"+i+"</span></li>"  );
    			  /* 
    			     $("ul.days").append(
    		              $("<li></li>").append(
    		                $("<span></span>").text(i).addClass("active")
    		              ) 
    		           )
    		       */
    		  }
    		  else{
    			  $("ul.days").append($("<li></li>").text( i ));
    		  }
		  } // for
      }
      
      function getDayOfWeek(year, month, date){
    	  var d = new Date( year, month-1, date );
    	  return  d.getDay();  //   ์ผ(0) ~ ํ† (6)
      }
      
      function getLastDay(year, month){
    	  var lastDay = 0;
    	  var d = new Date( year, month ); // 2022.12.01 - ํ•˜๋ฃจ =  ์ผ
    	  d.setDate(0);
    	  // console.log( d.toDateString() );  Wed Nov 30 2022
    	  lastDay = d.getDate();
    	  return lastDay ;
      }
      
      changeDate(); // 2022 / 11
////////////////////////////////////////////////////////////////////////////////////
   function changeCalendar(  value ){
	   // alert(  (typeof month) + "/" + (typeof value) );
	   month =  Number(month) +  value;
	   if( month == 0 ){
		   month = 12;
		   year--;
	   }else if( month == 13){
		   month = 1;
		   year++;
	   }
	   
	   // select ๋ณ€๊ฒฝ.
	   $("#cmbyear").val(  year );
	   $("#cmbmonth").val(  month ); 
	   changeDate();  // 1~ ๋งˆ์ง€๋ง‰๋‚ ์งœ.
	   
	   // console.log(   month + " /  "  + ( typeof month)   ) ;
	   printCalendar(year, month);
   }

์Šฌ๋ผ์ด๋”ฉ์‡ผ

 

<style>
    *{ box-sizing: border-box;}
    body{
		    margin: 0;
		    font-family: Verdana, sans-serif;
	}
	
	 .slideshow-container{
	     max-width: 1000px;
	     position: relative;
	     margin: auto;
   }
   
   .text{
    color:#2f2f2f;
    font-size: 15px;
    text-align: center;
    padding: 8px 12px;
    position: absolute;
    bottom: 8px;
    width:100%;    
  }
  
   .numbertext{
    color:#2f2f2f;
    font-size: 12px;
    padding: 8px 12px;
    position: absolute;
    top:0;
  }
  
   img{
     vertical-align: middle;
  }
  
  .mySlides{
     display: none;
  }
</style>
<style>
    .prev, .next{
      position: absolute;
      cursor: pointer;
      top:50%;
      color:white;
      width:auto;
      padding: 16px;
      margin-top: -22px;
      font-weight: bold;
      font-size:18px;
      border-radius: 0 3px 3px  0;
     /*  text-decoration: none; */
     
     transition:0.6s ease;
   }
   .next{
      right:0;
      border-radius: 3px 0 0 3px;
   }
   
   .prev:hover, .next:hover{
     background-color: rgba(0,0,0, 0.8);
   }
</style>

<style>
   .dots{
     position: absolute;
     top:10px;
     width:100%;
     text-align: center;
   }
   
   .dot{
     cursor: pointer;
     height: 15px;
     width: 15px;
     margin:0 2px;
     background-color: #bbb;
     border-radius: 50%;
     display: inline-block;
     transition:background-color 0.6s ease;
   }
   
   .active, .dot:hover{
     background-color: #717171;
   }
   
   .fade{
      animation-name:fade;
      animation-duration:1.5s;
      
      -webkit-animation-name:fade;
      -webkit-animation-duration:1.5s;      
   }
</style>
<style>
   /* ์• ๋‹ˆ๋ฉ”์ด์…˜ ํšจ๊ณผ */
   @keyframes fade{
     from{ opacity: 0.4 }
     to{ opacity:1}
   }
   @-webkit-keyframes fade{
     from{ opacity: 0.4 }
     to{ opacity:1}
   }
</style>
<div class="slideshow-container">
	<div class="mySlides fade">
		<div class="numbertext">1 / 3</div>
		<img src="../images/img_mountains_wide.jpg" style="width:100%" alt="" />
		<div class="text">Caption One</div>
	</div>
	<div class="mySlides fade">
		<div class="numbertext">2 / 3</div>
		<img src="../images/img_nature_wide.jpg" style="width:100%" alt="" />
		<div class="text">Caption Two</div>
	</div>
	<div class="mySlides fade">
		<div class="numbertext">3 / 3</div>
		<img src="../images/img_snow_wide.jpg" style="width:100%" alt="" />
		<div class="text">Caption Three</div>
	</div>
     
	<a class="prev"  onclick="changeSlide(-1)">&#10094;</a>
	<a class="next"  onclick="changeSlide(1)">&#10095;</a>
	 
	<div class="dots" style="text-align:center">
		<span class="dot" onclick="dotSlide(0)"></span>
		<span class="dot"  onclick="dotSlide(1)"></span>
		<span class="dot" onclick="dotSlide(2)"></span>
	</div>
</div>
    var slideIndex = 0;
    
    function showSlides(  sIndex ){
    	// js , [jQuery]
    	// ์ดˆ๊ธฐํ™” ์ž‘์—…
    	$(".slideshow-container .mySlides").css("display", "none");
    	$(".dots span.dot").removeClass("active");    	
    	// sIndex 
    	$(".slideshow-container .mySlides").eq(sIndex).css("display", "block");
    	$(".dots span.dot").eq(sIndex).addClass("active");    
    }
    
    showSlides( slideIndex  );
////////////////////////////////////////////////////////////////// 
   function changeSlide(value){  // -1,  1
	   slideIndex += value;
       // 0, 1, 2
       if( slideIndex == 3 )  slideIndex = 0;
       else if( slideIndex == -1 )  slideIndex = 2;
       
	   showSlides( slideIndex  );
   }
////////////////////////////////////////////////////////////////// 
   function dotSlide(sIndex){
	   slideIndex = sIndex;
	   showSlides( slideIndex  );
   }
   
   // ์ž๋™ ์Šฌ๋ผ์ด๋”ฉ ๊ธฐ๋Šฅ ์ถ”๊ฐ€

js ์ˆ˜ํ•™๊ฐ์ฒด( Math )

   Math ๊ฐ์ฒด๋Š” ์ƒ์„ฑ์ž๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค. 

   Math.์†์„ฑ.

   

   // new String()             + ์ƒ์„ฑ์ž

   // new Number()

   // new Array()

    console.log( Math.PI );
    console.log( Math.abs(-100) );
    console.log( Math.pow(2,3) );
    
    // ***
    console.log( Math.round( 3.1415 ) ); // 3 ๋ฐ˜์˜ฌ๋ฆผ ์†Œ์ˆ˜์  1 ์ž๋ฆฌ
    console.log( Math.ceil( 3.1415 ) ); // 3     ์˜ฌ๋ฆผ ์†Œ์ˆ˜์  1 ์ž๋ฆฌ
    console.log( Math.floor( 3.1415 ) ); // 3  ๋‚ด๋ฆผ ์†Œ์ˆ˜์  1 ์ž๋ฆฌ
    
    // ES6 ์ถ”๊ฐ€ : ์ •์ˆ˜ ๋ถ€๋ถ„์„ ๋ฐ˜ํ™˜.
    // Math.trunc()    
    console.log( Math.trunc(-4.2)  +" / "  + Math.floor(-4.2) );  // -4 / -5
    
    console.log(  Math.sign( -3.14) );  // 1    -1    0
    
    // Math.max(), Math.min()

js ๋ถ€์šธ(boolean)

    - true /  false

    - js Boolean ์ž๋ฃŒํ˜• 

      //console.log(   10 > 9 );
      //console.log(   Boolean(  10 > 9  ) );  // true            Boolean() ํ•จ์ˆ˜ - ์ˆ˜์‹ ์ฐธ/๊ฑฐ์ง“

      // [ js boolean ์ฃผ์˜. ]  ***
      console.log(  Boolean(  100  )  );  // ์ƒ์ˆ˜ true
      console.log(  Boolean(  3.14  )  );  // ์ƒ์ˆ˜ true
      console.log(  Boolean(  "hello"  )  );  // ๋ฌธ์ž์—ด ์ƒ์ˆ˜ true
      console.log(  Boolean(  "null"  )  );  // ๋ฌธ์ž์—ด ์ƒ์ˆ˜ true

      // [ value ์ด ์—†๋Š” ๋ชจ๋“  ๊ฒƒ๋“ค์€ false ์ด๋‹ค. ]
      console.log(   Boolean( 0 ) );  // false
      console.log(   Boolean( "" ) );  // false
      console.log(   Boolean( null ) );  // false
      var name;         // undefined
      console.log(   Boolean( name ) );  // false
      console.log(   Boolean( NaN ) );  // false
      
      // var age = 0;
      // var age = null;
      //var age = "";
      //if( age ){    	  
      //}

      if(  10/"hello" ){   NaN  false
    	  
      }else{
    	  
      }
      
      // var x = false;  // boolean
      // var x = new Boolean( false );  ๊ฐ€๋Šฅํ•˜์ง€๋งŒ ์‚ฌ์šฉ X,  object

js ์ œ์–ด๋ฌธ

    1. if, if~else, if ~else if~ else

    2. switch ~case + break

    3. for / foreach

    4. while(){}

        do{

        }while();

์ •์ˆ˜ : <input type="text"  id="txtnum">
<br>
<p id="demo"></p>

if

   $("#txtnum").keydown(function() {
   	    if( event.keyCode == 13 ){
   	    	// ํ•„์ˆ˜ ์ž…๋ ฅ ์‚ฌํ•ญ + ์ •์ˆ˜ ์ž…๋ ฅ.  isNaN() , ์ •๊ทœํ‘œํ˜„์‹   /^\d+$/
   	    	 
   	    	if( !$("#txtnum").val().trim()){         
   	    		alert("ํ•„์ˆ˜ ์ž…๋ ฅ!!!");
   	    		return ;
   	    	}
   	    	 
   	    	var n = Number(  $("#txtnum").val() );
   	    	if ( n % 2 == 0) {
				// ์ง์ˆ˜
			} else {
                 // ํ™€์ˆ˜
			}
   	    }
   });

switch

  $("#txtnum").keydown(function() {
	  var n = Number(  $("#txtnum").val() );
	  switch (   n % 2  ) {
		case 0:
			break;
		default:
			break;
		}

while

  $("#txtnum").keydown(function() {
	  if( event.keyCode == 13 ){
				  var n = Number(  $("#txtnum").val() );
				  var content = "";
				  
				  var sum = 0;
				  /*
				  for (var i = 1; i <= n; i++) {
					  content += i+"+";
					  sum += i;
				 } // for
				 */
				 var i = 1;
				 while( i <= n ){
					 content += i+"+";
					  sum += i;
					  i++;
				 } // while			 
				 
				  content += "=" + sum;
				  
				  $("#demo").html( content );
				  
				  //for ( var x in iterable) { }
				  //for ( var x of iterable) { }
	  } // if
	   
   });

for in

    // 1. for in ๋ฌธ์€ ๊ฐ์ฒด(๊ฐœ์ฒด)์˜ ์†์„ฑ์„ ๋ฐ˜๋ณตํ•˜๋Š” ๋ฐ˜๋ณต๋ฌธ
    // 2. ํ˜•์‹
    //           for( let  prop   in object){
    //}
    
    var m = [ 3,5,2,4,1];
    // console.log(  typeof m );  // ๋ฐฐ์—ด๋„ ํƒ€์ž…์€ object ์ด๋‹ค. 
    
    // x = 0,1,2,3,4           index
    for ( var idx in m) {
		// console.log( idx ) ;
		console.log(   m[idx] );
	}
    
    // 
    Array.forEach( function (elt, index, array){
    	
    } )
    // js object
     var person = {
    		// ์†์„ฑ๋ช…:์†์„ฑ๊ฐ’
    		name:"admin", 
    		age:20
    };
    
    // person.name
    // person["name"]
    
    for ( var p in person) {  // object
		console.log(  person[p]  );
    	
        // for in๋ฌธ์•ˆ์—์„œ person.idx๋Š” ์™œ ์•ˆ๋˜๋‚˜์š”??
        // 		console.log( person.p);
        // console.log(  typeof p );  // string
	}

for of

    [js ์ œ์–ด๋ฌธ( for of)]

    - ES6(2015) ์ƒˆ๋กœ ์ถ”๊ฐ€๋œ ๋ฌธ

    - IE ์ง€์›๋˜์ง€ ์•Š์•„์š”.

    - ๋ฐ˜๋ณต ๊ฐ€๋Šฅํ•œ ๊ฐ์ฒด์˜ ๊ฐ’์„ ๋ฐ˜๋ณตํ•˜๋Š” ๋ฌธ

      (Arrays, Strings, [ Maps, NodeLists ]X ๋ฐ˜๋ณต๊ฐ€๋Šฅํ•œ ๋ฐ์ดํ„ฐ ๊ตฌ์กฐ.  )

    var m = [3,5,2,4,1];
    for ( var n of m) {
		console.log( n );
	}
    
    var msg = "hello world!";

    for (var i = 0; i < msg.length; i++) {
		console.log(  msg.charAt(i) );
	} // for

    for (let ch of msg) {
		console.log("["+ch + "]")
	}

<style>
 .container{
    width: 500px;
  }
  
  .collapsible{
    background-color: #777;
    color:white;
    cursor: pointer;
    padding: 18px;
    width: 100%;
    border: none;
    text-align: left;
    outline:none;
    font-size: 15px;
  }
  
   /* ::๊ฐ€์ƒ ์š”์†Œ ์„ ํƒ์ž*/
  .collapsible::after{
    content:'\002B';  /*   +  */
    color:white;
    float: right;
    font-weight: bold;
    margin-left: 5px;
  }
  
  .collapsible:hover ,  .active{
    background-color: #555;
  }
  
  .content{
    padding: 0 18px;
    background-color: #f1f1f1;
    max-height: 0;  /* ์˜ค๋ฒ„ํ”Œ๋กœ์šฐ๊ฐ€ ๋ฐœ์ƒ.. */
    overflow: hidden;   /* ์ˆจ๊ธฐ๊ธฐ */
    
    transition:max-height  0.2s ease-out;
  }
  
  .active::after{
      content:'\2212';   /*  -  */
   }
</style>
<div class="container">

<button class="collapsible">Section 1</button>
<div class="content">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nulla iure aliquam soluta minima impedit ratione laboriosam autem omnis. Doloribus eius incidunt totam iure deleniti a officia blanditiis rem recusandae officiis.</div>

<button class="collapsible">Section 2</button>
<div class="content">
 Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nulla iure aliquam soluta minima impedit ratione laboriosam autem omnis. Doloribus eius incidunt totam iure deleniti a officia blanditiis rem recusandae officiis.
 Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nulla iure aliquam soluta minima impedit ratione laboriosam autem omnis. Doloribus eius incidunt totam iure deleniti a officia blanditiis rem recusandae officiis.
 Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nulla iure aliquam soluta minima impedit ratione laboriosam autem omnis. Doloribus eius incidunt totam iure deleniti a officia blanditiis rem recusandae officiis.
 </div>

<button class="collapsible">Section 3</button> 
<div class="content">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nulla iure aliquam soluta minima impedit ratione laboriosam autem omnis. Doloribus eius incidunt totam iure deleniti a officia blanditiis rem recusandae officiis.</div>

</div>
    // js , [jquery]
    $(".collapsible").click(function() {
    	$(this).toggleClass("active");
    	// ํด๋ฆญ๋œ ๋ฒ„ํŠผ ๋’ค์˜  <div class="content">
    	if(  $(this).next().css("max-height")  != "0px" ){
    		$(this).next().css("max-height",  "0px"  );
    	}else{
    		$(this).next().css("max-height",  $(this).next().prop("scrollHeight")+"px"  );	
    	} 
    	
    });

* toggleclass : ํด๋ž˜์Šค์†์„ฑ ์žˆ์œผ๋ฉด ์ œ๊ฑฐํ•˜๊ณ  ์—†์œผ๋ฉด ์ค€๋‹ค๋Š” ๋œป

* ํด๋ฆญ๋œ ๋ฒ„ํŠผ ๋’ค ๊ธ€ ์ฐพ์•„์™€์„œ (next())  max-height์†์„ฑ์„ ์คŒ

0px์•„๋‹ˆ๋ฉด -> 0px

0px์ด๋ฉด -> max height ์†์„ฑ ์ฃผ๋Š”๋ฐ, ๊ทธ ๋’ค ์†์„ฑ๊ฐ’(scrollheight) ์ฝ์–ด์™€์„œ px๋‹จ์œ„ ๋ถ™์—ฌ์คŒ

(scrollheight ์•„๋งˆ ๊ธธ๊ฒŒ ๋‚ด๋ฆฌ๋Š” ์†์„ฑ)

  • ๋„ค์ด๋ฒ„ ๋ธ”๋Ÿฌ๊ทธ ๊ณต์œ ํ•˜๊ธฐ
  • ๋„ค์ด๋ฒ„ ๋ฐด๋“œ์— ๊ณต์œ ํ•˜๊ธฐ
  • ํŽ˜์ด์Šค๋ถ ๊ณต์œ ํ•˜๊ธฐ
  • ์นด์นด์˜ค์Šคํ† ๋ฆฌ ๊ณต์œ ํ•˜๊ธฐ