-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy path09 - Objects.html
49 lines (40 loc) · 1.08 KB
/
09 - Objects.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Getting Started with JavaScript</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css">
<style>
body {
padding: 30px;
}
</style>
</head>
<body>
<!-- 🔥🔥🔥🔥 start javascript 🔥🔥🔥🔥 -->
<script>
const hero = {
name: 'Bruce Wayne',
alias: 'Batman',
catchphrase: 'To the Batcave!',
speak: function () {
return 'Attention! ' + this.catchphrase;
},
attack: function (sound) {
// return '(punches bad guy) ' + sound;
return `(punches bad guy) ${sound}`;
}
};
// access a property
const thingToLookFor = 'alias';
console.log(hero.name); // Bruce Wayne
console.log(hero['name']); // Bruce Wayne
console.log(hero[thingToLookFor]); // Batman
// accessing methods (functions)
console.log(hero.speak);
console.log(hero.speak());
console.log(hero.attack('POWWWWW'));
'this is my string'.toUpperCase();
</script>
</body>
</html>