From 20f67f1ba2eb986b1f18afcf915ff089cbf98192 Mon Sep 17 00:00:00 2001 From: Della Bella Date: Wed, 5 Nov 2025 22:47:40 +0000 Subject: [PATCH 1/4] Authors EXcercise ...Practing Object.Values ( ) Object.keys( ) Objects.entries ( ) --- Sprint-2/debug/author.js | 88 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 85 insertions(+), 3 deletions(-) diff --git a/Sprint-2/debug/author.js b/Sprint-2/debug/author.js index 8c2125977..886551127 100644 --- a/Sprint-2/debug/author.js +++ b/Sprint-2/debug/author.js @@ -10,7 +10,89 @@ const author = { age: 40, alive: true, }; - -for (const value of author) { - console.log(value); + const onlyValues = Object.values(author); +for (const value of onlyValues) { } + console.log(onlyValues); + + + + + const studentScores = { + math: 85, + science: 92, + history: 78, + art: 95 +}; + + let totalSum = 0; + const sumArray = Object.values(studentScores); + + for (const value of sumArray){ + totalSum = totalSum + value; //totalSum += value; + } +console.log(totalSum); + + +// Goal: Calculate the sum of all the student's scores. +// You need to get an array of just the numbers (values) first. +// How would you get an array like: [85, 92, 78, 95] from studentScores? + +// Exercise 2: List All Ingredients + +// You have a recipe object, and you want to list out all the ingredients. + + + + +// Goal: Print a list of all ingredient names (keys) from the 'ingredients' object. +// You need to get an array like: ["flour", "milk", "eggs", "sugar", "bakingPowder"] +// from the 'ingredients' object. + +// need to make object interable = array and get the key.values ofthe object + +const recipe = { + title: "Pancakes", + servings: 4, + ingredients: { + flour: "1 cup", + milk: "1 cup", + eggs: "2 large", + sugar: "2 tbsp", + bakingPowder: "2 tsp", + }, + instructions: "Mix ingredients, cook on griddle.", +}; + +const ingredientsList = Object.keys(recipe.ingredients); + + +for (const value of ingredientsList) { +console.log(value); +}; + + +// Exercise 3: Format User Preferences + +// A user's preferences are stored in an object. You want to display each preference as "Key: Value". + + +const userSettings = { + theme: "dark", + notifications: true, + language: "en-US", + autoplayVideo: false +}; + + let userPreferences = Object.entries(userSettings); + + for (const values of userPreferences) { + console.log(values); //console.log(`${key}: ${value}`); //console.log(`${pair[0]}: ${pair[1]}`); + }; + +// Goal: Log each setting in the format "Key: Value". +// Example output: +// "theme: dark" +// "notifications: true" +// ... +// This requires working with both the key and the value for each item. \ No newline at end of file From b43986ff1be0fee2b28de5b703b4d7248831d814 Mon Sep 17 00:00:00 2001 From: Della Bella Date: Wed, 5 Nov 2025 23:39:29 +0000 Subject: [PATCH 2/4] Recipes Object Practice --- Sprint-2/debug/recipe.js | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/Sprint-2/debug/recipe.js b/Sprint-2/debug/recipe.js index 6cbdd22cd..f3cdb4139 100644 --- a/Sprint-2/debug/recipe.js +++ b/Sprint-2/debug/recipe.js @@ -1,15 +1,23 @@ // Predict and explain first... - +// the code try to print a array in a single line of ingredients and also has +// syntax erros // This program should log out the title, how many it serves and the ingredients. +// I need to get the values but firnt need to make the object interable=use Object.value // Each ingredient should be logged on a new line // How can you fix it? const recipe = { - title: "bruschetta", - serves: 2, - ingredients: ["olive oil", "tomatoes", "salt", "pepper"], +title: "bruschetta", +serves: 2, +ingredients: ["olive oil", "tomatoes", "salt", "pepper"], }; -console.log(`${recipe.title} serves ${recipe.serves} - ingredients: -${recipe}`); +let menuList = Object.values(recipe.ingredients); + +console.log (`${recipe.title}`); + console.log (`serves ${recipe.serves}`); + + +for (const ingredientName of menuList) { +console.log(ingredientName); +} \ No newline at end of file From b978c71e562f3833b2b262ae3c28814193805737 Mon Sep 17 00:00:00 2001 From: Della Bella Date: Sun, 9 Nov 2025 14:18:05 +0000 Subject: [PATCH 3/4] Debug- adress Object --- Sprint-2/debug/address.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sprint-2/debug/address.js b/Sprint-2/debug/address.js index 940a6af83..42993182d 100644 --- a/Sprint-2/debug/address.js +++ b/Sprint-2/debug/address.js @@ -1,5 +1,7 @@ // Predict and explain first... +// adress is a object and use label to acess the information not a index + // This code should log out the houseNumber from the address object // but it isn't working... // Fix anything that isn't working @@ -12,4 +14,4 @@ const address = { postcode: "XYZ 123", }; -console.log(`My house number is ${address[0]}`); +console.log(`My house number is ${address["houseNumber"]}`); From f6eca06c7ccd4df32cd29fa5b60ceba4fdab8dda Mon Sep 17 00:00:00 2001 From: Della Bella Date: Sun, 16 Nov 2025 11:47:23 +0000 Subject: [PATCH 4/4] Fixed erros & best formating --- Sprint-2/debug/address.js | 2 +- Sprint-2/debug/author.js | 47 ++++++++++++++++----------------------- 2 files changed, 20 insertions(+), 29 deletions(-) diff --git a/Sprint-2/debug/address.js b/Sprint-2/debug/address.js index 42993182d..a0a90be91 100644 --- a/Sprint-2/debug/address.js +++ b/Sprint-2/debug/address.js @@ -1,6 +1,6 @@ // Predict and explain first... -// adress is a object and use label to acess the information not a index +//An address is an object. Access its details using names (like 'houseNumber'), not by counting them with numbers // This code should log out the houseNumber from the address object // but it isn't working... diff --git a/Sprint-2/debug/author.js b/Sprint-2/debug/author.js index 886551127..b1aee82e6 100644 --- a/Sprint-2/debug/author.js +++ b/Sprint-2/debug/author.js @@ -10,29 +10,26 @@ const author = { age: 40, alive: true, }; - const onlyValues = Object.values(author); +const onlyValues = Object.values(author); + for (const value of onlyValues) { + console.log(value); } - console.log(onlyValues); - - - - const studentScores = { +const studentScores = { math: 85, science: 92, history: 78, - art: 95 + art: 95, }; - let totalSum = 0; - const sumArray = Object.values(studentScores); - - for (const value of sumArray){ - totalSum = totalSum + value; //totalSum += value; - } -console.log(totalSum); +let totalSum = 0; +const sumArray = Object.values(studentScores); +for (const value of sumArray) { + totalSum += value; +} +console.log(totalSum); // Goal: Calculate the sum of all the student's scores. // You need to get an array of just the numbers (values) first. @@ -42,9 +39,6 @@ console.log(totalSum); // You have a recipe object, and you want to list out all the ingredients. - - - // Goal: Print a list of all ingredient names (keys) from the 'ingredients' object. // You need to get an array like: ["flour", "milk", "eggs", "sugar", "bakingPowder"] // from the 'ingredients' object. @@ -66,33 +60,30 @@ const recipe = { const ingredientsList = Object.keys(recipe.ingredients); - for (const value of ingredientsList) { -console.log(value); -}; - + console.log(value); +} // Exercise 3: Format User Preferences // A user's preferences are stored in an object. You want to display each preference as "Key: Value". - const userSettings = { theme: "dark", notifications: true, language: "en-US", - autoplayVideo: false + autoplayVideo: false, }; - let userPreferences = Object.entries(userSettings); +let userPreferences = Object.entries(userSettings); - for (const values of userPreferences) { - console.log(values); //console.log(`${key}: ${value}`); //console.log(`${pair[0]}: ${pair[1]}`); - }; +for (const values of userPreferences) { + console.log(values); //console.log(`${key}: ${value}`); //console.log(`${pair[0]}: ${pair[1]}`); +} // Goal: Log each setting in the format "Key: Value". // Example output: // "theme: dark" // "notifications: true" // ... -// This requires working with both the key and the value for each item. \ No newline at end of file +// This requires working with both the key and the value for each item.