Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions extraObjIH.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
const ironhacker = {
firstName: 'Marko',
age: 39,
favoriteLanguage: 'JavaScript',
isSatisfied: true,
'works at': null,
isRemote: false,
address: {
country: 'Portugal',
city: 'Lisbon',
},
};

// 1: Update age to 40 and console.log the new value
// ... your code here

ironhacker.age = 40;
console.log(ironhacker.age);

// 2: Update ironhacker's place of work to 'Google' and console.log the new value
// ... your code here
ironhacker.placeofwork = "Google";

console.log(ironhacker.placeofwork)

// 3: Remove the 'isRemote' property and console.log the new value of 'isRemote' to make sure it is undefined
// ... your code here
delete ironhacker.isRemote;
console.log(ironhacker.isRemote)

// 4: Add a new property: 'didGraduate' and set it to a valid boolean value and console.log the new value
// ... your code here
ironhacker.didGraduate = true;
console.log(ironhacker.didGraduate)

// 5: console.log all keys (property names) of the ironhacker object (you can print them as an array or as individual console.logs)
// ... your code here
console.log(ironhacker)

// 6: check if ironhacker has property 'favoriteLanguage'. Console.log a boolean true or false depending if 'favoriteLanguage' exists as a preperty
// ... your code here
const hasfavoriteLanguage = ironhacker.hasOwnProperty("favoriteLanguage");
console.log(hasfavoriteLanguage);


// 7: BONUS: update the property city to be 'Porto' and console.log the new value
// - Note that it is nested inside another object.



// 8: BONUS: Complete the following function:
// it should print the country and city of the person with the following string structure:
// Our ironhacker FIRST_NAME is from CITY, COUNTRY

function countryAndCity(person) {
// make sure to use the parameter person for their properties and to return the string
}

console.log('Bonus 8.', countryAndCity(ironhacker));

81 changes: 68 additions & 13 deletions src/books.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,71 @@


// Your code here:
const booksArray = [];
const booksArray = [
{
title: "The Old Man and the Sea",
pages: 128,
author: "Ernest Hemingway",
details: {
language: "English",
description: "One of Hemingway's most famous works, it tells the story of Santiago..."
}
},
{
title: "The Airbnb Story",
pages: 256,
author: "Leigh Gallagher",
details: {
language: "English",
description: "This is the remarkable behind-the-scenes story of the creation and growth of Airbnb..."
}
},
{
title: "Educated - A Memoir",
pages: 352,
author: "Tara Westover",
details: {
language: "English",
description: "Educated is an account of the struggle for self-invention..."
}
},
{
title: "The Art of Learning",
pages: 288,
author: "Josh Waitzkin",
details: {
language: "English",
description: "The Art of Learning takes readers through Waitzkin's unique journey to excellence. He explains in clear detail how a well-thought-out, principled approach to learning is what separates success from failure."
}
}
];




// Iteration 2 | Book Details
function getBookDetails() {
// Your code here:

// Iteration 2 | Book Details
function getBookDetails(book) {
return (book.title + " - " + book.author + " - " + book.pages + " pages");
}

console.log(getBookDetails(booksArray[0])); //test



// Iteration 3 | Delete Language
// Your code here:

booksArray.forEach(book => {
delete book.details.language;
});



// Iteration 4 | Estimated Reading Time
// Your code here:

booksArray.forEach(book => {
book.readingTime = Math.ceil(book.pages * 500 / 90);
});



Expand All @@ -86,15 +129,27 @@ const dictionary = {
],
};

function booksByAuthor() {
function booksByAuthor(dictionary) {
// Your code here:

}


newArray = [];
for(const author in dictionary){
dictionary[author].forEach(book => {
newArray.push({
author: author,
title: book[0],
pages: book[1]
});
});
}
return newArray;
}

// Bonus: Iteration 6 | Average Page Count
function averagePageCount() {
// Your code here:
function averagePageCount(booksArray) {
// Your code here:booksArray.forEach(book => {
var averagePage = 0;
for(var i = 0; i < booksArray.length; i++){
averagePage += booksArray[i].pages;
} return averagePage / booksArray.length;

}