-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaScript10.html
More file actions
217 lines (179 loc) Β· 8.67 KB
/
JavaScript10.html
File metadata and controls
217 lines (179 loc) Β· 8.67 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<html lang='ko'>
<head>
<title>κ°μ²΄</title>
<style>
.area-big{
height:400px;
border:1px solid black;
background:lightgray;
}
.area{
height:200px;
border:1px solid black;
background:lightgray;
}
</style>
</head>
<body>
<h1>κ°μ²΄</h1>
<h3>κ°μ²΄ μ μΈ λ° νΈμΆ</h3>
<p>κ°μ²΄λ ν€ κ°μ μ¬μ©νμ¬ μμ±μ μλ³νλ€.<br>
μ€κ΄νΈ {}λ₯Ό μ¬μ©νμ¬ κ°μ²΄λ₯Ό μμ±νκ³ , μμ±μλ λͺ¨λ μλ£νμ΄ μ¬ μ μλ€.</p>
<button onclick="test1();">μ€ννμΈ</button>
<div id="area1" class="area-big"></div>
<script>
function test1(){
var product = {
pName : "Dry Mango",
type : 'Pickle',
ingredient : ['mango', 'sugar'],
origin : 'Philippines'
}
console.log(product);
var area1 = document.getElementById("area1");
area1.innerHTML += "product : " + product + "<br><br>";
area1.innerHTML += "<b>κ°μ²΄λͺ
['μμ±λͺ
']μΌλ‘ μ κ·ΌνκΈ°<b><br>";
area1.innerHTML += "product['pName'] : " + product['pName'] + '<br>';
area1.innerHTML += "product['type'] : " + product['type'] + '<br>';
area1.innerHTML += "product['ingredient'] : " + product['ingredient'] + '<br>';
area1.innerHTML += "product['ingredient'][0] : " + product['ingredient'][0] + '<br>';
area1.innerHTML += "product['ingredient'][1] : " + product['ingredient'][1] + '<br>';
area1.innerHTML += "product['origin'] : " + product['origin'] + '<br>';
area1.innerHTML += "<b>κ°μ²΄λͺ
.μμ±λͺ
μΌλ‘ μ κ·ΌνκΈ°<b><br>";
area1.innerHTML += "product.pName : " + product.pName + '<br>';
}
</script>
<hr>
<h3>κ°μ²΄μ ν€ μλ³μ ν
μ€νΈ</h3>
<p>κ°μ²΄μ ν€λ λͺ¨λ λ¬Έμμ΄μ μ¬μ©ν μ μλ€.<br>
μλ³μλ‘ μ¬μ©ν μ μλ λ¨μ΄λ₯Ό ν€λ‘ μ¬μ©ν κ²½μ°μλ 무쑰건 λκ΄νΈλ₯Ό μ¬μ©ν΄μΌ κ°μ²΄μ μμμ μ κ·Όν μ μλ€.
</p>
<button onclick="test2();">μ€ννμΈ</button>
<div id="area2" class="area"></div>
<script>
function test2(){
var objTest = {
'I love you' : 'κΉμ©μΉ',
'I hate !@#$%^()' : 'Bκ°μμ₯'
}
var area2 = document.getElementById("area2");
console.log(objTest);
// area2.innerHTML += 'I love you : ' + objTest.I love you + "<br>";
// area2.innerHTML += "I hate !@#$%^() : " + objTest.'I hate !@#$%^()' + "<br>";
area2.innerHTML += 'I love you : ' + objTest['I love you'] + "<br>";
area2.innerHTML += "I hate !@#$%^() : " + objTest['I hate !@#$%^()'] + "<br>";
}
</script>
<h3>κ°μ²΄μ λ©μλ μμ±</h3>
<p>κ°μ²΄μ μμ± μ€ ν¨μ μλ£νμΈ μμ±μ λ©μλλΌκ³ λΆλ₯Έλ€.</p>
<button onclick = "test3();">μ€ννμΈ</button>
<div id="area3" class="area"></div>
<script>
function test3(){
var area3 = document.getElementById("area3");
var dog = {
name : '볡μ€μ΄',
eat : function(food){
// κ°μ²΄ λ΄μμ μμ μ μμ±μ νΈμΆν λμλ λ°λμ μ¨μΌν¨
// κ°λ°μλ€μ΄ νν μ€μ ν μ μλ λΆλΆμΌλ‘
// λ°λμ thisλ₯Ό λͺ
μμ μΌλ‘ μ¨μ€μΌ ν¨
area3.innerHTML += this.name + 'κ° ' + food + 'λ₯Ό λ¨Ήκ³ μλ€μ~ λ©λ©λ©λ©!';
}
}
dog.eat('λ°λλ');
}
</script>
<hr>
<h3>κ°μ²΄μ λ°λ³΅λ¬Έ</h3>
<p>κ°μ²΄μ μμ±μ μ΄ν΄λ³Ό λμλ λ¨μ forλ¬ΈμΌλ‘λ μ¬μ© λΆκ°λ₯ νκ³ , for inλ¬Έμ μ¬μ©ν΄μΌ νλ€.</p>
<button onclick="test4();">μ€ννμΈ</button>
<div id = "area4" class="area"></div>
<script>
function test4(){
var game = {
title : "DIABLO3",
price : "35,000μ",
language : "νκ΅μ΄ μ§μ",
supportOS : "window 32/64",
service : true
}
var area4 = document.getElementById("area4");
for(var key in game){
area4.innerHTML += key + " : " + game[key] + "<br>";
}
// for inλ¬Έμ key(μμ±λͺ
)μ νμ©ν΄ μμ±κ°μ μ κ·Όν λλ λ°λμ []λ₯Ό μ¨μΌ ν¨
}
</script>
<hr>
<h3>inκ³Ό with ν€μλ</h3>
<p>in : κ°μ²΄ λ΄λΆμ ν΄λΉ μμ±μ΄ μλμ§ νμΈνλ ν€μλ<br>
with : μ½λλ₯Ό μ€μ¬μ£Όλ ν€μλ, νΈμΆμ κ°μ²΄λͺ
μλ΅μ΄ κ°λ₯νλ€.</p>
<label>μ΄λ¦ : </label><input type="text" id="name"><br>
<label>κ΅μ΄ : </label><input type="text" id="kor"><br>
<label>μμ΄ : </label><input type="text" id="eng"><br>
<label>μν : </label><input type="text" id="math"><br>
<button onclick = "test5();">μ€ννμΈ</button>
<div id = "area5" class = "area-big"></div>
<script>
function test5(){
var name1 = document.getElementById('name').value;
var kor1 = parseInt(document.getElementById('kor').value);
var eng1 = parseInt(document.getElementById('eng').value);
var math1 = parseInt(document.getElementById('math').value);
var student = {
name : name1,
kor : kor1,
eng : eng1,
math : math1
}
var area5 = document.getElementById("area5");
area5.innerHTML += "<b>in ν€μλ ν
μ€νΈ </b><br>";
area5.innerHTML += 'studentκ°μ²΄μ nameμ΄λΌλ μμ±μ΄ μλμ§ νμΈ : ' + ('name' in student) + "<br>";
area5.innerHTML += 'studentκ°μ²΄μ eng123μ΄λΌλ μμ±μ΄ μλμ§ νμΈ : ' + ('eng123' in student) + "<br>";
area5.innerHTML += "<b>with ν€μλ ν
μ€νΈ</b><br>";
// area5.innerHTML += "νμμ΄λ¦ : " + student.name + "<br>";
// area5.innerHTML += "μνμ μ : " + student.math + "<br>";
// area5.innerHTML += "μ΄μ : " + (student.kor + student.eng + student.math) + "<br>";
// area5.innerHTML += "νκ· : " + (student.kor + student.eng + student.math)/3 + "<br>";
with(student){
area5.innerHTML += "νμμ΄λ¦ : " + name + "<br>";
area5.innerHTML += "μνμ μ : " + math + "<br>";
area5.innerHTML += "μ΄μ : " + (kor + eng + math) + "<br>";
area5.innerHTML += "νκ· : " + (kor + eng + math)/3 + "<br>";
}
}
</script>
<hr>
<h3>κ°μ²΄μ μμ± μΆκ°μ μ κ±°</h3>
<p>μ²μ κ°μ²΄ μμ± μ΄ν μμ±μ μΆκ°νκ±°λ μ κ±°νλ κ²μ λμ μΌλ‘ μμ±μ μΆκ°νλ€ νΉμ μ κ±°νλ€ λΌλ ννμ μ</p>
<button onclick = "test6();">μ€ννμΈ</button>
<div id = "area6" class="area"></div>
<script>
function test6(){
// μμ΄ λΉ κ°μ²΄ μμ±
var student = {};
console.log(student);
// κ°μ²΄μ μμ± μΆκ°
student.name = 'κΉμ©μΉ';
student.hobby = 'μμ
κ°μ';
student.strength = 'νλ‘κ·Έλλ°';
student.dream = 'μ¬νμκ°';
console.log(student);
student.toString = function(){
var str = "";
for(var key in student){
if(key != 'toString'){
str+= key + " : " + student[key] + "<br>";
}
}
return str;
}
var area6 = document.getElementById("area6");
area6.innerHTML = student.toString();
area6.innerHTML = student;
}
</script>
<br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br>
</body>
</html>