-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
38 lines (35 loc) · 882 Bytes
/
script.js
File metadata and controls
38 lines (35 loc) · 882 Bytes
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
/**
* Create a monster object, populate some HTML to display its properties.
*/
const updatemonster = (update) => {
let main = document.querySelector("main");
main.innerHTML = markup(monster);
console.info(update);
};
const monster = {
name: "Graveyard Ghoul",
hp: 30,
color: "grey",
numberOfArms: 4,
attack: false,
toggleAttack: function (attack) {
this.attack = attack;
updatemonster(`Monster status changed.`);
},
};
const markup = (monster) => {
return `
<div>
<h3>${monster.name}</h3>
<ul>
<li>Hit Points: ${monster.hp}</li>
<li>Color: ${monster.color}</li>
<li>Number of arms: ${monster.numberOfArms}</li>
<li>Attack Mode: ${monster.attack ? "Attack" : "Peaceful"}</li>
</ul>
</div>
`;
};
const main = document.createElement("main");
main.innerHTML = markup(monster);
document.body.appendChild(main);