Skip to content
Closed
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
4 changes: 3 additions & 1 deletion Sprint-2/debug/address.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Predict and explain first...

//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...
// Fix anything that isn't working
Expand All @@ -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"]}`);
75 changes: 74 additions & 1 deletion Sprint-2/debug/author.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,80 @@ const author = {
age: 40,
alive: true,
};
const onlyValues = Object.values(author);

for (const value of author) {
for (const value of onlyValues) {
console.log(value);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason you are closing the bracket right here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it .it was a mistake. I had an empty loop. fixed. thanks


Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting: no need for the extra blank lines, usually we have a maximum of one blank line

const studentScores = {
math: 85,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually have the object keys and values indented one more line to make it easier to read

science: 92,
history: 78,
art: 95,
};

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.
// 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.
22 changes: 15 additions & 7 deletions Sprint-2/debug/recipe.js
Original file line number Diff line number Diff line change
@@ -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);
}
Loading