-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
53 lines (43 loc) · 1.43 KB
/
index.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
<!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>Document</title>
</head>
<body>
<script>
//attributes: name, health, speed(private), strength(private)
function Ninja(name) {
//speed and strength are 3 by default, health is 100 by default
let speed = 3;
let strength = 3;
let health = 100;
this.name = name;
//method: sayName() log Ninja's name
Ninja.prototype.sayName = function() {
console.log("My ninja name is " + this.name + "!");
return this
};
//method: showStats() show ninja's strength, speed, and health
Ninja.prototype.showStats = function() {
console.log("Name: " + this.name + ", Health: " + health + ", Speed: " + speed + ", Strength: " + strength)
return this
}
// method: drinkSake() add 10 health to ninja
Ninja.prototype.drinkSake = function() {
health += 10;
return health
};
}
/*---------- example output:-------- */
const ninja1 = new Ninja("Hyabusa");
ninja1.sayName();
// -> "My ninja name is Hyabusa!"
ninja1.showStats();
// -> "Name: Hayabusa, Health: 100, Speed: 3, Strength: 3"
console.log(ninja1.drinkSake());
</script>
</body>
</html>