-
-
Save ross-u/5bf636fde73b363dcecce3000767071b to your computer and use it in GitHub Desktop.
Solution - JS | Objects - Objectively
This file contains hidden or 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
var joke = { | |
category: 'Chuck Norris Jokes', | |
url: 'https://api.chucknorris.io/jokes/I5_UU3f7Q2e2qao2TJz9aw', | |
content: 'Anything you can do, Chuck Norris does better.' | |
} | |
// Task 1 | |
// Using `for..in`, `console.log` all property names of the `joke` object, | |
// concatenating string `joke.` first. | |
// Expected result : 'joke.category', `joke.url`, `joke.content` | |
for (var key in joke) { | |
console.log(`joke.${key}`) | |
} | |
// Task 2 | |
// Using `Object.keys` get the array of property names (keys) from the object joke | |
// and `console.log` that array. | |
var propertyNames = Object.keys(joke); | |
console.log(propertyNames); | |
// Task 3 | |
// Using keyword `delete`, remove the property `url` from the object joke. | |
delete joke.url; | |
console.log(joke); | |
// Task 4 | |
// Using dot notation add method (function) `hint` to the joke object. | |
// Method should `console.log`: "The joke is stored in the property .content" | |
joke.hint = function() { | |
console.log("The joke is stored in the property .content") | |
} | |
joke.hint(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment