class Vampire:
def __init__(self, props):
self.location = props['location']
self.birthDate = props['birthDate']
self.deathDate = props['deathDate']
self.weaknesses = props['weaknesses']
def get_age(self):
return self.calc_age()
def calc_age(self):
return self.deathDate - self.birthDate
Dracula = Vampire({
'location': 'Transylvania',
'birthDate': 1428,
'deathDate': 1476,
'weaknesses': ['Sunlight', 'Garlic']
})
1<!doctype html>
2<html lang="en">
3 <head>
4 <meta charset="UTF-8" />
5 <title>Dracula</title>
6 </head>
7 <body>
8
9 <h1>Vampires</h1>
10
11 <form>
12 <label for="location">Location</label>
13 <input type="text" name="location" value="Transylvania" />
14 <label for="birthDate">Birth Date:</label>
15 <input type="number" name="birthDate" value="1428" />
16 <label for="deathDate">Death Date:</label>
17 <input type="number" name="deathDate" value="1476" />
18 <label for="weaknesses">Weaknesses:</label>
19 <input type="checkbox" name="weaknesses" value="Sunlight" checked />
20 <input type="checkbox" name="weaknesses" value="Garlic" checked />
21
22 <button type="submit">Submit</button>
23 </form>
24
25 <script>
26
27 const form = document.querySelector("form");
28 form.addEventListener("submit", (e) => {
29 const { birthDate, deathDate } = e.target;
30 const age = deathDate.value - birthDate.value;
31 });
32 </script>
33 </body>
34</html>
# Vampires
| Name | Value |
| ---------- | ---------------- |
| location | Transylvania |
| birth date | 1428 |
| death date | 1476 |
| weaknesses | Sunlight, Garlic |
> The **age** is the `deathDate` minus the `birthDate`