본문 바로가기

Learning/HTML&JavaScript

자바스크립트

 

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <meta http-equiv="X-UA-Compatible" content="ie=edge">

    <title>맛보기 예제</title>

</head>

<body>

    <script>

        var age = prompt("당신의 나이는?", "0");

        if(age >= 20){

            document.write("당신은 성인입니다.");

        }else{

            document.write("당신은 미성년자입니다.");

        }

    </script>

</body>

</html>

 

 

 


 

 

<!DOCTYPE html>

<html lang="ko">

<head>

    <meta charset="UTF-8">

    <title>선언문</title>

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

    <script>

        document.write("선언문");

    </script>

</head>

<body>

</body>

</html>

 

 

 

 


 

<!DOCTYPE html>

<html lang="ko">

<head>

    <meta charset="UTF-8">

    <title> 외부 자바스크립트 연동 </title>

    <script>

        var box;

        box=100;

        box=30;

        document.write(box, "<br>");

        var a="javascript";

        document.write(a, "<br>");

        var str="자바스크립트";

        var num=100;

        document.write(typeof num, "<br>");

        document.write(typeof str);

    </script>

</head>

<body>

</body>

</html>

 

 

 


 

<!DOCTYPE html>

<html lang="ko">

<head>

    <meta charset="UTF-8">

    <title> 산술 연산자 </title>

    <script>

        var num1 = 15;

        var num2 = 2;

        var result;

        result=num1+num2;

        document.write(result, "<br>");

        result=num1*num2;

        document.write(result, "<br>");

        result=num1/num2;

        document.write(result, "<br>");

        result=num1%num2;

        document.write(result, "<br>");

        var t1="학교종이";

        var t2="땡땡땡";

        result=t1+t2;

        document.write(result, "<br>");

        

        var num1=10;

        var num2=3;

        num1+=num2;

        document.write(num1);

    </script>

</head>

<body>

</body>

</html>

 

 


 

 

<!DOCTYPE html>

<html lang="ko">

<head>

<meta charset="UTF-8">

<title> 복합대입 연산자-테이블 만들기 </title>

<script>

    var str="<table border='1'>";

        str+="<tr>"

        str+="<td>1</td><td>2</td><td>3</td>";

        str+="</tr>"

        str+="</table>"

    document.write(str);

</script>

</head>

<body>

</body>

</html>

 

 

 


 

 

<!DOCTYPE html>

<html lang="ko">

<head>

    <meta charset="UTF-8">

    <title> 비교 연산자 </title>

    <script>

        var a = 10;

        var b = 20;

        var c = 10;

        var f = "20";

        var result;

        

        result=a>b;

        document.write(result,"<br>");

        result=a<=b;

        document.write(result,"<br>");

        result=a!=b;

        document.write(result,"<br>");

        result=b===f;

        document.write(result,"<br>");

    </script>

</head>

<body>

</body>

</html>

 

스크립트에서 '같다'표시는 === 이다.

 

 

 

 


<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title> 삼항 조건 연산자 </title>
<script>
	var a = 10;
	var b = 3;
	//var result;

	var result=a>b? "자바스크립트":"hello";
	document.write(result,"<br>");
</script>
</head>
<body>
</body>
</html>


 

 

<!DOCTYPE html>

<html lang="ko">

<head>

<meta charset="UTF-8">

<title> 적정 몸무게 구하기 </title>

<script>

    var name=prompt("이름:","");

    var weight=prompt("몸무게:","0");

    var height=prompt("키:","0");



    var normal_w=(height-100)*0.9;

    var result=weight>=normal_w-5 && weight<=normal_w+5;

    result=result? "적정체중":"적정체중이 아닙니다.";

    document.write(name+"님은 "+result);

</script>

</head>

<body>

</body>

</html>

 

 

 

 

 


<!DOCTYPE html>

<html lang="ko">

<head>

<meta charset="UTF-8">

<title> 종합실습1-1 </title>

<script>

    var price1 = 3000;

    var price2 = 6000;

    var price3 = 3000;



    var total=price1+price2+price3;

    

    total=total>10000? total-10000+"원 초과":"관리잘함";

    document.write(total);

</script>

</head>

<body>

</body>

</html>

 


 

'Learning > HTML&JavaScript' 카테고리의 다른 글

자바스크립트 객체  (0) 2020.07.31
자바스크립트 제어문  (0) 2020.07.31
CSS3 선택자  (0) 2020.07.24
HTML 멀티미디어  (0) 2020.07.24
HTML5 시멘틱 태그  (0) 2020.07.24