-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
36 lines (31 loc) · 911 Bytes
/
script.js
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
let num = document.querySelector('.theDiv');
class Marker {
constructor(color, inkLevel) {
this.color = color;
this.inkLevel = inkLevel;
}
print(text) {
let textOut = '';
for (let i = 0; i < text.length; i++) {
if (this.inkLevel >= 0.5) {
textOut += text[i];
if (text[i] != " ") {
this.inkLevel -= 0.5;
}
}
}
return document.write(`<p style="color: ${this.color}">${textOut}</p>`),
console.log(this.inkLevel);
}
}
const mark = new Marker('orange', 50);
mark.print("Hello, i am the printed text!")
class RefillableMarker extends Marker {
refill() {
this.inkLevel = 100;
}
}
const refMark = new RefillableMarker('red', 5);
refMark.print("Hello, i am the mark ");
refMark.refill()
refMark.print("Hello, i am the printed text!");