From 3ccbef97690c57a1397f97cd6215c84881abc773 Mon Sep 17 00:00:00 2001 From: Thomas Wiik Date: Fri, 20 Sep 2024 15:53:05 +0200 Subject: [PATCH 1/2] Halfway there --- src/core.js | 16 ++++++++++++++-- src/extension.js | 8 ++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/core.js b/src/core.js index 6380dd5..6ace2be 100644 --- a/src/core.js +++ b/src/core.js @@ -2,32 +2,44 @@ const person = { age: 32, size: 'Small' } // 1. Give the person object a name property with the value Matt +person.name = 'Matt' // 2. Remove the size property from the person +delete person.size // 3. Increase the person's age by 11 +person.age += 11 // 4. Add an instruments property to the person, initialised as an empty array +person.instruments = [] // 5. Add the following instruments to the persons instruments array: Guitar, Piano, Vocals +person.instruments.push('Guitar', 'Piano', 'Vocals') // 6. Using an index on the instruments array, set the mainInstrument variable below // to the third instrument in the array -const mainInstrument = undefined +const mainInstrument = person.instruments[2] // 7. Add a profession property to the person, which is an object +person.profession = {} // 8. Add a name property to the profession object with the value Musician +person.profession.name = "Musician" // 9. Add a friends property to the person, which is an empty array +person.friends = [] // 10. Add two objects to the persons friends array with the following properties: // Friend one: name - Chris, age - 46 // Friend two: name - Dom, age - 43 +const friendOne = { name: 'Chris', age: 46} +const friendTwo = { name: 'Dom', age: 43} +person.friends.push(friendOne) +person.friends.push(friendTwo) // 11. Using an index on the persons friends array, set the bestFriend variable below // to the name of the first friend in the array -const bestFriend = undefined +const bestFriend = person.friends[0].name // Don't change the code below this line module.exports = { diff --git a/src/extension.js b/src/extension.js index 38f327f..f2e86b1 100644 --- a/src/extension.js +++ b/src/extension.js @@ -19,10 +19,10 @@ const book = { const isbn13 = '978-0132350884' // 1. Set this to the book name - using the book object -const name = '' +const name = book.name // 2. Set this to the isbn 10 value - using the book object -const isbn10 = '' +const isbn10 = book.isbn.isbn10 // Do not modify this basket object directly const basket = { @@ -42,10 +42,10 @@ const basket = { } // 3. Set this variable to the length of the baskets voucher codes array - using the basket object -const numberOfVoucherCodes = null +const numberOfVoucherCodes = basket.voucherCodes.length // 4. Set this variable to the first element in of the baskets voucher codes array - using the basket object -const firstVoucherCode = null +const firstVoucherCode = basket.voucherCodes[0] // Do not edit this exported object module.exports = { From 620433ce7627236e13ca1a742414a98edafd1133 Mon Sep 17 00:00:00 2001 From: Thomas Wiik Date: Sat, 21 Sep 2024 09:59:23 +0200 Subject: [PATCH 2/2] Solved all exercises --- src/advanced.js | 22 +++++++++++++++++++--- src/core.js | 12 +++++++++--- src/extension.js | 25 +++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 6 deletions(-) diff --git a/src/advanced.js b/src/advanced.js index 692c1fb..17adc4f 100644 --- a/src/advanced.js +++ b/src/advanced.js @@ -1,13 +1,29 @@ // 1. create a const variable called item1 and set it to an object with the following properties: // name of 'item1', price of 400, and quantity of 4, hasDiscount of true, discount of 0.3 -const item1 = undefined +const item1 = { + name: 'item1', + price: 400, + quantity: 4, + hasDiscount: true, + discount: 0.3 +} // 2. create a const variable called item2 and set it to an object with the following properties: // name of 'item2', price of 300, and quantity of 3, hasDiscount of false, discount of 0.0 -const item2 = undefined +const item2 = { + name: 'item2', + price: 300, + quantity: 3, + hasDiscount: false, + discount: 0.0 +} + // 3. create a const variable called shoppingBasket and set it to an object with the following properties: // items - an array containing item1 and item2, and shopName called 'Sheepmart' -const shoppingBasket = undefined +const shoppingBasket = { + items: [item1, item2], + shopName: 'Sheepmart' +} module.exports = { item1, diff --git a/src/core.js b/src/core.js index 6ace2be..bd701d5 100644 --- a/src/core.js +++ b/src/core.js @@ -24,7 +24,7 @@ const mainInstrument = person.instruments[2] person.profession = {} // 8. Add a name property to the profession object with the value Musician -person.profession.name = "Musician" +person.profession.name = 'Musician' // 9. Add a friends property to the person, which is an empty array person.friends = [] @@ -32,8 +32,14 @@ person.friends = [] // 10. Add two objects to the persons friends array with the following properties: // Friend one: name - Chris, age - 46 // Friend two: name - Dom, age - 43 -const friendOne = { name: 'Chris', age: 46} -const friendTwo = { name: 'Dom', age: 43} +const friendOne = { + name: 'Chris', + age: 46 +} +const friendTwo = { + name: 'Dom', + age: 43 +} person.friends.push(friendOne) person.friends.push(friendTwo) diff --git a/src/extension.js b/src/extension.js index f2e86b1..33242e6 100644 --- a/src/extension.js +++ b/src/extension.js @@ -24,6 +24,21 @@ const name = book.name // 2. Set this to the isbn 10 value - using the book object const isbn10 = book.isbn.isbn10 +// Delete book dimension key +delete book.dimensions + +// Book pages should be 464 +book.pages = 464 + +// Book should not contain asin key +delete book.isbn.asin + +// Book ISBN 13 should be 978-0132350884 +book.isbn.isbn13 = isbn13 + +// Book category should be programming +book.category = 'Programming' + // Do not modify this basket object directly const basket = { items: [ @@ -47,6 +62,16 @@ const numberOfVoucherCodes = basket.voucherCodes.length // 4. Set this variable to the first element in of the baskets voucher codes array - using the basket object const firstVoucherCode = basket.voucherCodes[0] +// 5. Set the price of apples to 2 +basket.items[0].price = 2 + +// 6. Add 4 oranges with the price of 0.75 to the end of the items list +basket.items.push({ + name: 'Oranges', + quantity: 4, + price: 0.75 +}) + // Do not edit this exported object module.exports = { name,