-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavascript-basic1.html
More file actions
116 lines (93 loc) · 2.61 KB
/
javascript-basic1.html
File metadata and controls
116 lines (93 loc) · 2.61 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<html>
<head>
<title>Javascript Bare</title>
</head>
<body>
<script type="text/javascript">
// var water = function (amount) {
// var happiness = 0
// happiness += amount;
// console.log('You watered the ' + this.plantType);
// };
// var greenHouse = {
// room1: {
// plantType: 'strawberries',
// happiness: 3,
// water: water
// },
// room2: {
// plantType: 'eggplants',
// happiness: 1,
// water: water
// }
// };
// greenHouse.room1.water(2);
// console.log('Strawberries should have 5 happiness:', greenHouse.room1.happiness);
// greenHouse.room2.water(23);
// console.log('Eggplants should have 24 happiness:', greenHouse.room2.happiness);
// var sprayPixieDust = function (person) {
// person.pixieDust += 1;
// };
// var wendy = {
// fly: function () {
// if (this.pixieDust < 2) {
// return 'thump!';
// }
// else {
// return 'I can fly!';
// }
// }
// };
// console.log('Wendy should not be able to fly (yet):', wendy.fly());
// sprayPixieDust(wendy);
// console.log('Wendy should STILL not be able to fly:', wendy.fly());
// sprayPixieDust(wendy);
// console.log('Can she fly now?', wendy.fly());
// var wishingWell = {
// coinCount: 2,
// wishToss: function () {
// this.coinCount += 1;
// },
// stealCoins: function(num){
// if (this.coinCount - num > 0){
// this.coinCount -= num;
// }else(this.coinCount = 0)
// }
// };
// wishingWell.wishToss();
// console.log('Wishing well should have 3 coins:', wishingWell.coinCount);
// wishingWell.stealCoins(2);
// console.log('Wishing well should have 1 coin:', wishingWell.coinCount);
// wishingWell.stealCoins(5);
// console.log('Wishing well should have 0 coins:', wishingWell.coinCount);
// var musicPlayer = {
// currentlyPlaying: null,
// play: function(song){
// this.currentlyPlaying = song;
// }
// };
// musicPlayer.play('Giant Steps');
// console.log('Music player should be playing "Giant Steps":', musicPlayer.currentlyPlaying);
// musicPlayer.play('Blue Glasses');
// console.log('Music player should be playing "Blue Glasses":', musicPlayer.currentlyPlaying);
// var revealSecret = function () {
// return this.secret;
// };
// var incept = function (person, func) {
// person.inception = func; //spy.inception = revealSecret
// var result = person.inception();
// alert(person.name + " said: " + result);
// };
// var spy = {
// name: "Mr. Smith",
// secret: "I like pie"
// };
// incept(spy, revealSecret);
// var otherSpy = {
// name: "Dr. Tran",
// secret: "I can lick my elbow"
// };
// incept(otherSpy, revealSecret);
</script>
</body>
</html>