-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathscript.js
More file actions
48 lines (38 loc) · 1.42 KB
/
script.js
File metadata and controls
48 lines (38 loc) · 1.42 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
$(document).ready(function() {
var koreanCities = ["Busan", "Seoul", "Masan", "Daegu", "Gimhae", "Ulsan", "Jejudo"];
/*
In order to calculate the Korean age with the JavaScript 'this' keyword
we have to create a method (i.e. a function inside an object). When 'this' is
used inside of an object, it refers to the GLOBAL OBJECT, which would be the
browser window. There is no .age property of the global object, so my old code
always returned undefined. Now if we use 'this' inside of a method, then it will
refer to the intended object, in this case myLoveProfile.
*/
var myLoveProfile = {
name: "Stephen",
single: false,
age: 29,
koreanAge: function() {
return this.age + 1;
},
currentCity: koreanCities[0]
};
console.log(myLoveProfile.koreanAge());
var possibleMatch= {
name: "Ji-yeon",
single: true,
age: 23,
currentCity: koreanCities[0]
};
$('#loveButton').on('click', function() {
if (myLoveProfile.currentCity === possibleMatch.currentCity && myLoveProfile.single && possibleMatch.single) {
$('h1').text('You are a match!');
} else if (myLoveProfile.currentCity !== possibleMatch.currentCity && myLoveProfile.single && possibleMatch.single) {
$('h1').text('Do you like long distance?');
} else if (!myLoveProfile.single && myLoveProfile.currentCity !== possibleMatch.currentCity) {
$('h1').text('You are a cheater!!');
} else {
$('.message').append("<h2 style='color: red;'>No match!</h2");
}
});
});