-
Notifications
You must be signed in to change notification settings - Fork 76
/
Copy path07-objects.html
44 lines (38 loc) · 1.07 KB
/
07-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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Getting Started with JavaScript</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/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>