forked from AI-Collaboratory/INST742-git
-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathobjects_answer.html
71 lines (51 loc) · 1.26 KB
/
objects_answer.html
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
<html>
<head>
<style type="text/css">
.square {
margin-top: 50px;
margin-left: 100px;
}
div {
margin-bottom: 20px;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
function Square (width, height, color, classname, left, top){
this.width = width;
this.height = height;
this.background = color;
this.left = left;
this.top = top;
// creates a div tag inside the "container" object.
this.sq = document.getElementById("container").appendChild(document.createElement("div"))
this.sq.setAttribute("class", classname);
this.sq.setAttribute("style", "height:" + this.height);
this.sq.style.width = this.width;
this.sq.style.background = this.background;
// task 4
this.sq.style.position = "absolute";
this.sq.style["margin-left"] = this.left;
this.sq.style["margin-top"] = this.top;
this.changeColor = function(c){
this.background = c;
this.sq.style.background = this.background;
}
// Task 3
this.putSentence = function(s){
this.sq.innerHTML = s;
}
}
s1 = new Square("200px", "50px", "grey", "square", "1px", "2px");
// Task 1
s1.changeColor("blue");
// Task 2
s2 = new Square("200px", "50px", "orange", "square", "100px", "200px");
// task 3
s1.putSentence("hello");
s2.putSentence("hi");
</script>
</body>
</html>