-
-
Notifications
You must be signed in to change notification settings - Fork 220
London | 25-ITP-September |Gislaine Della Bella | Sprint 2 | Debug #827
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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); | ||
| } | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
| 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); | ||
| } |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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