본문 바로가기

   
Programming/Javascript

JavaScript 조건문 사용방법

반응형

JavaScript 조건문 사용방법

<html>

<head>

    <title>조건문</title>

 

             <script type="text/javascript">

                    //조건문

                    //           var n = 10;

 

                    //           if (n > 0)

                    //           {

                    //                  alert("양수");

                    //           }

                    //           else if (n < 0)

                    //           {

                    //                  alert("음수");

                    //           }

                    //           else

                    //                  alert("");

 

                    //숫자(0이면 false, 0이 아니면 true)

                    //문자열(""이면 false, ""이 아니면 true

                    //           if (num != 0)

                    //           {

                    //                  alert("");

                    //           }

                    //           else

                    //           {

                    //                  alert("거짓");

                    //           }

 

 

 

//                  var name = "홍길동";

 

//                  switch (name)

//                  {

//                         case "홍길동":

//                               alert("과장");

//                               break;

//                         case "아무게":

//                               alert("부장");

//                               break;

                    //                  }

 

                    //반복문

                    //- 루프변수 선언시 var 사용 x 예전 브라우저에선 오류가 나는 경우가 있다.

                    for (var i = 0; i < 10; i++)

                    {

                           //alert(i);

                    }

 

                    var n = 0;

                    while (n < 10)

                    {

                           //alert(n);

                           n++;

                    }

 

                    //foreach 와 같은 구문

//                  for (var i in o)

//                  {

//                  }

             </script>

 

</head>

<body>

 

</body>

</html>

반응형