본문 바로가기

Javascript

(35)
switch문 case문의 값은 상수(리터럴)만 가능 예) case 1 : casee 2.7 : case "Seoul" : case true : case 2+3 : //계산되어서 case 5 : 랑 동일 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 Document switch문 var price = 0; var coffee = prompt("무슨 커피 드릴까요?","에스프레소"); switch (coffee) { case "에스프레소": // price = 2000; //break;..
제어문 - 선택문 - if, else if, else (+예시 학점 매기기, 월 계절 맞추기) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 Document 제어문 -> 선택문 -> if, else if, else gender = "남자"; //if문 ()안에는 반드시 true, false값이 들어간다. if(gender=="남자"){ document.writeln("당신은 남자입니다."); }else{ document.writeln("당신은 여자입니다."); } document.writeln(" "); //제어문 전체에 적용 : // 실행되는 코드에 {}중괄호가 없으면 밑에 또는 옆에 있는 한줄만 적용. //실행되는 코드가 두줄 ..
문자열 연산자 서론에 설명 조금 더하기 //String operator 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 Document 문자열 연산 document.writeln("abc"+23+" "); document.writeln("35"+23+" "); document.writeln(35+23+"abc"+" "); //순서유의 s1 = "aaa"; s2 = "bbb"; document.writeln((s1==s2)+" "); document.writeln((s1!==s2)+" "); http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter http://colorscrip..
함수들 - alert() prompt() confirm() alert() 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Document function a(){ alert("클릭하셨군요!"); } 클릭 http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs prompt("메시지", "기본값 입력") 사용자로부터 문자열을 입력 받아 리턴 confirm() 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 1..
조건 연산자(삼항연산자) 조건? true:false 조건? true:false true, false부분 타입 같아야 합니다! 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Document 조건 연산 var a = 3, b = 5; document.writeln((a>b)?a:b); document.writeln((a>b)?"a가 큽니다.":"b가 큽니다."); http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs ?..
비교 연산자, 논리 연산자 // Comparison operator, Logical operator 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 Document 비교, 논리 연산 var a = 13, b = 7; document.writeln(a==b); document.writeln(a!=b);//!는 부정(not) document.writeln(a>b); document.writeln(a>=b); document.writeln(a=2)); document.writeln((3>4)||(4>=2)); http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scri..
산술 연산자 // Arithmetic Operators 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 Document 산술연산 var x = 32; var total = 100 + x * 2 / 4 - 3; var div = x / 10; var mod = x % 2; document.writeln(x+" "); document.writeln(total+" "); document.writeln(div+" "); document.writeln(mod+" "); document.writeln("================== "); //////////////////////////////////////////////// var a = 3, b = 3, c = ..
상수 //literal 상수(literal) : 데이터 값 그 자체 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 Document 상수 //파란색은 예약어 var oct = 015; var hex = 0x14; var con = true; document.writeln(oct);//8진수 document.writeln(hex);//16진수 document.writeln(con);//boolean //자바스크립트는 자바보다 유연해요 아래에 처럼 "문자열" '문자열' 둘다 가능 document.writeln('문자열1'); document.writeln("문자열1"); http://colorscripter.com/info#e" target="_blank" style="c..