This repository was archived by the owner on Jan 3, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathexercise-3.js
More file actions
58 lines (48 loc) · 1.56 KB
/
exercise-3.js
File metadata and controls
58 lines (48 loc) · 1.56 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
/*
Given the same "house" object again
Write the code for the functions as per the description above them
*/
let kinningParkHouse = {
address: "1 Kinning Park",
price: 180000,
currentOwner: {
firstName: "Margaret",
lastName: "Conway",
email: "margaret@fake-emails.com"
}
};
let parkAvenueHouse = {
address: "50 Park Avenue",
price: 195000,
currentOwner: {
firstName: "Marie",
lastName: "McDonald",
email: "marie.m@real-emails.com"
}
};
/*
DO NOT EDIT ANYTHING ABOVE THIS LINE
WRITE YOUR CODE BELOW
*/
// returns the full name (first name + last name) of the owner of the house
function getOwnerFullName(house) {
return `${house.currentOwner.firstName} ${house.currentOwner.lastName}`;
}
// returns an array of the owners' email addresses of the two houses
function getEmailAddresses(house1, house2) {
return `${house1.currentOwner.email} ${house2.currentOwner.email}`;
}
// returns the address for the cheapest house out of the two
function getCheapestAddress(house1, house2) {
if(house1.price < house2.price){
return house1.address;
}else{
return house2.address;
}
}
/*
DO NOT EDIT ANYTHING BELOW THIS LINE
*/
console.log(`Expected result: Margaret Conway. Actual result: ${getOwnerFullName(kinningParkHouse)}`);
console.log(`Expected result: margaret@fake-emails.com, marie.m@real-emails.com. Actual result: ${getEmailAddresses(kinningParkHouse, parkAvenueHouse)}`);
console.log(`Expected result: 1 Kinning Park. Actual result: ${getCheapestAddress(parkAvenueHouse, kinningParkHouse)}`);