Created
July 11, 2020 08:57
-
-
Save pads/e83a9aeea001386d0f4de639fc64dc92 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://github.com/CodeYourFuture/JavaScript-Core-2-Homework/blob/master/Week-1/InClass/C-more-complex-objects/exercise-3.js | |
/* | |
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)}`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment