<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title>04_변수.html</title>
<style></style>
</head>
<body>
<h3>상수와 변수</h3>
<script>
//참조 https://www.w3schools.com/js/js_variables.asp
//1. 상수 constant
//-> 고정 불변의 값
document.write(3);
document.write(-5);
document.write(3.4);
document.write('A');
document.write("가");
document.write(true);
document.write("<hr>");
//2. 변수 variable
//->변수의 성격: var, let, const, nothing
// 1) var
var a=3; // a라는 변수를 선언하고 3을 저장
var b=5;
var c=7;
document.write(a); //변수
document.write(b);
document.write(c);
document.write(1+2+3);
document.write(a+b+c);
document.write("a"); //상수
document.write("<hr>");
// 2) nothing : 변수를 선언하지 않아도 사용할 수 있다
name="손흥민";
age=25;
height=178.5;
document.write(name);
document.write(age);
document.write(height);
document.write("<hr>");
//변수는 새로운 값으로 대입하면서 사용한다
a=2;
b=4;
c=6;
name="김연아";
age=30;
height=165.9;
document.write(a);
document.write(b);
document.write(c);
document.write(name);
document.write(age);
document.write(height);
document.write("<hr>");
// 3) let
//->반드시 변수를 선언하고 사용한다
let i=2;
let j=4;
let k=i+j;
document.write(k);//6
// 에러. let으로 선언한 i변수를 이중으로 선언할 수 없다
//let i=8;
// 4) const
//-> 변수를 상수화
const x=10;
document.write(x);
//에러. 변수값을 바꿀 수 없다
//x=9;
</script>
</body>
</html>
05_document
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title>05_document.html</title>
<style></style>
</head>
<body>
<h3>document 객체</h3>
<div id="demo"></div>
<script>
/*
● 객체 Object
->속성 객체명.멤버변수
->메소드 객체명.멤버함수()
*/
document.write(123);
document.write("대한민국");
document.write("<hr>");
// + 연산자
document.write(3+5); //8
document.write("<hr>");
document.write(3+"5"); //35
document.write("<hr>");
document.write("3"+5); //35
document.write("<hr>");
document.write("3"+"5"); //35
document.write("<hr>");
document.write("3+5"); //3+5
document.write("<hr>");
let name="손흥민";
let age=25;
let height=178.9;
document.write("이름:" + name + "<hr>");
document.write("나이:" + age + "<hr>");
document.write("키:" + height + "<hr>");
//자바스크립트에서 HTML tag 사용시 문자열 처리해서 사용한다
document.write("개나리<br><p>진달래<p>");
document.write("<img src='../../images/monkey.png'>");
document.write("<hr>");
///////////////////////////////////////////////////////
let str=""; //빈문자열 (글자갯수 0개)
str=str+"ONE";
document.write(str);
document.write("<hr>");
str=str+"TWO";
document.write(str);
document.write("<hr>");
str=str+"THREE";
document.write(str); //ONETWOTHREE
document.write("<hr>");
str=""; // 문자열 지우기
document.write("#" + str + "#");
document.write("<hr>");
//////////////////////////////////////////////////
//본문 <body>에 있는 id 속성 접근
//1)순수 JavaScript
//document.getElementById("demo")
//document.getElementById("demo").innerText="아이티윌";
//2)jQuery 접근 (jQuery라이브러리 필요함)
//$("#demo")
//$("#demo").val("아이티윌")
//////////////////////////////////////////////////
//연스) 이름, 나이, 키 값들을 표작성을 해서 id=demo에 출력하시오
name="김연아";
age=30;
height=165.7;
let result=""; //결과값
result = result + "<table border='1'>";
result = result + "<tr>";
result = result + " <th>이름</th>";
result = result + " <td>" + name + "</td>";
result = result + "</tr>";
result = result + "<tr>";
result = result + " <th>나이</th>";
result = result + " <td> " + age + "</td>";
result = result + "</tr>";
result = result + "<tr>";
result = result + " <th>키</th>";
result = result + " <td> " + height + "</td>";
result = result + "</tr>";
result = result + "</table>"
//결과값을 문자열로 출력
//document.getElementById("demo").innerText = result; //$("#demo").text(result)
//결과값을 HTML tag 형식으로 출력
document.getElementById("demo").innerHTML = result; //$("#demo").html(result)
</script>
</body>
</html>