fix(curriculum): remove average calculations from workshop-recipe-tracker (#63758)

This commit is contained in:
l3onhard
2025-12-15 05:43:40 +01:00
committed by GitHub
parent 30f6f714c2
commit 25e292901d
15 changed files with 345 additions and 561 deletions
@@ -16,13 +16,13 @@ Start by creating an empty array named `recipes`. This is the array you'll push
You should create an array named `recipes`.
```js
assert.isArray(recipes)
assert.isArray(recipes);
```
Your `recipes` array should be empty.
```js
assert.isEmpty(recipes)
assert.isEmpty(recipes);
```
# --seed--
@@ -11,14 +11,12 @@ Create an object named `recipe1`. Inside the `recipe1` object, create a `name` p
Also inside the `recipe1` object, create an `ingredients` property with an array as the value. The array should have `spaghetti`, `Parmesan cheese`, `pancetta`, and `black pepper` inside it.
Create a `ratings` property with an array value. The array should have `4`, `5`, `4`, and `5` inside it.
# --hints--
You should create an object named `recipe1`.
```js
assert.isObject(recipe1)
assert.isObject(recipe1);
```
Your `recipe1` object should have a `name` property.
@@ -42,7 +40,7 @@ assert.property(recipe1, 'ingredients');
Your `ingredients` property should have an array value.
```js
assert.isArray(recipe1.ingredients)
assert.isArray(recipe1.ingredients);
```
The array value of your `ingredients` property should have `spaghetti`, `Parmesan cheese`, `pancetta`, and `black pepper` in it.
@@ -51,24 +49,6 @@ The array value of your `ingredients` property should have `spaghetti`, `Parmesa
assert.deepEqual(recipe1.ingredients, ["spaghetti", "Parmesan cheese", "pancetta", "black pepper"]);
```
Your `recipe1` object should have a `ratings` property.
```js
assert.property(recipe1, "ratings");
```
Your `ratings` property should have an array value.
```js
assert.isArray(recipe1.ratings)
```
The array value of your `ratings` property should have `4`, `5`, `4`, and `5` in it.
```js
assert.deepEqual(recipe1.ratings, [4, 5, 4, 5]);
```
# --seed--
## --seed-contents--
@@ -13,18 +13,16 @@ Create a `recipe2` object with the following properties and values:
| ----------- | ------- |
| `name` | `Chicken Curry` |
| `ingredients` | `["chicken breast", "coconut milk", "curry powder", "onion", "garlic"]` |
| `ratings` | `[4, 5, 5, 5]` |
| `cookingTime` | `42` |
| `totalIngredients` | `null` |
| `difficultyLevel` | `''` |
| `averageRating` | `null` |
| `difficultyLevel` | `""` |
# --hints--
You should create an object named `recipe2`.
```js
assert.isObject(recipe2)
assert.isObject(recipe2);
```
Your `recipe2` object should have a `name` property.
@@ -48,7 +46,7 @@ assert.property(recipe2, "ingredients");
Your `ingredients` property should have an array value.
```js
assert.isArray(recipe2.ingredients)
assert.isArray(recipe2.ingredients);
```
The array value of your `ingredients` property should have `chicken breast`, `coconut milk`, `curry powder`, `onion` and `garlic` in it.
@@ -57,24 +55,6 @@ The array value of your `ingredients` property should have `chicken breast`, `co
assert.deepEqual(recipe2.ingredients, ["chicken breast", "coconut milk", "curry powder", "onion", "garlic"]);
```
Your `recipe2` object should have a `ratings` property.
```js
assert.property(recipe2, "ratings");
```
Your `ratings` property should have an array value.
```js
assert.isArray(recipe2.ratings)
```
The array value of your `ratings` property should have `4`, `5`, `5`, and `5` in it.
```js
assert.deepEqual(recipe2.ratings, [4, 5, 5, 5]);
```
Your `recipe2` object should have a `cookingTime` property.
```js
@@ -117,18 +97,6 @@ Your `difficultyLevel` property should be set to an empty string.
assert.deepEqual(recipe2.difficultyLevel, "");
```
Your `recipe2` object should have an `averageRating` property.
```js
assert.property(recipe2, "averageRating");
```
Your `averageRating` property should be set to `null`.
```js
assert.isNull(recipe2.averageRating);
```
# --seed--
## --seed-contents--
@@ -137,14 +105,12 @@ assert.isNull(recipe2.averageRating);
const recipes = [];
const recipe1 = {
name: 'Spaghetti Carbonara',
ingredients: ['spaghetti', 'Parmesan cheese', 'pancetta', 'black pepper'],
name: "Spaghetti Carbonara",
ingredients: ["spaghetti", "Parmesan cheese", "pancetta", "black pepper"],
cookingTime: 22,
totalIngredients: null,
difficultyLevel: '',
ratings: [4, 5, 4, 5],
averageRating: null,
};
difficultyLevel: ""
};
--fcc-editable-region--
@@ -1,19 +1,17 @@
---
id: 66fbcf750a62784cf11f5630
title: Step 6
title: Step 7
challengeType: 1
dashedName: step-6
dashedName: step-7
---
# --description--
A third `recipe3` object has been filled in for you. It has the same properties as `recipe1` and `recipe2`.
You should now push the three objects into the `recipes` array. To do this, you can use the `push()` method.
Use the `push()` method to push all the recipe objects into the `recipes` array. Make sure to push `recipe1`, `recipe2`, and `recipe3` in that order.
Also delete the `recipe1Name`, `recipe2Name`, `recipe1CookingTime`, and `recipe2CookingTime` variables, and the `console.log` statements which log those variables.
Also delete the `recipe1Name`, `recipe2CookingTime` and `recipe3Ingredients` variables, and the `console.log` statements which log those variables.
# --hints--
@@ -79,46 +77,37 @@ assert.deepEqual(recipes, [recipe1, recipe2, recipe3]);
const recipes = [];
const recipe1 = {
name: 'Spaghetti Carbonara',
ingredients: ['spaghetti', 'Parmesan cheese', 'pancetta', 'black pepper'],
name: "Spaghetti Carbonara",
ingredients: ["spaghetti", "Parmesan cheese", "pancetta", "black pepper"],
cookingTime: 22,
totalIngredients: null,
difficultyLevel: '',
ratings: [4, 5, 4, 5],
averageRating: null,
difficultyLevel: ""
};
const recipe2 = {
name: 'Chicken Curry',
ingredients: ['chicken breast', 'coconut milk', 'curry powder', 'onion', 'garlic'],
name: "Chicken Curry",
ingredients: ["chicken breast", "coconut milk", "curry powder", "onion", "garlic"],
cookingTime: 42,
totalIngredients: null,
difficultyLevel: '',
ratings: [4, 5, 5, 5],
averageRating: null,
difficultyLevel: ""
};
const recipe3 = {
name: 'Vegetable Stir Fry',
ingredients: ['broccoli', 'carrot', 'bell pepper'],
name: "Vegetable Stir Fry",
ingredients: ["broccoli", "carrot", "bell pepper"],
cookingTime: 15,
totalIngredients: null,
difficultyLevel: '',
ratings: [4, 3, 4, 5],
averageRating: null,
difficultyLevel: ""
};
--fcc-editable-region--
const recipe1Name = recipe1.name;
console.log(recipe1Name);
const recipe2Name = recipe2.name;
console.log(recipe2Name);
const recipe1CookingTime = recipe1.cookingTime;
console.log(recipe1CookingTime);
const recipe2CookingTime = recipe2.cookingTime;
console.log(recipe2CookingTime);
const recipe3Ingredients = recipe3.ingredients;
console.log(recipe3Ingredients);
--fcc-editable-region--
```
@@ -1,96 +0,0 @@
---
id: 66fbcf750a62784cf11f5631
title: Step 7
challengeType: 1
dashedName: step-7
---
# --description--
In the next few steps you will work on calculating the average rating, the total ingredients, and the difficulty level for each recipe in the `recipes` array.
Start by creating a `getAverageRating` function that takes a single argument, which is an array with ratings. Inside the function, calculate the average rating from the array passed to the function.
Your `getAverageRating` function must return a number.
# --hints--
You should create a `getAverageRating` function.
```js
assert.isFunction(getAverageRating)
```
Your `getAverageRating` function should have a single parameter.
```js
assert.lengthOf(getAverageRating, 1);
```
Your `getAverageRating` function should return a number.
```js
assert.isNumber(getAverageRating(recipe1.ratings))
```
`getAverageRating(recipe1.ratings)` should return `4.5`.
```js
assert.strictEqual(getAverageRating(recipe1.ratings), 4.5)
```
`getAverageRating(recipe2.ratings)` should return `4.75`.
```js
assert.strictEqual(getAverageRating(recipe2.ratings), 4.75)
```
`getAverageRating(recipe3.ratings)` should return `4`.
```js
assert.strictEqual(getAverageRating(recipe3.ratings), 4)
```
# --seed--
## --seed-contents--
```js
const recipes = [];
const recipe1 = {
name: 'Spaghetti Carbonara',
ingredients: ['spaghetti', 'Parmesan cheese', 'pancetta', 'black pepper'],
cookingTime: 22,
totalIngredients: null,
difficultyLevel: '',
ratings: [4, 5, 4, 5],
averageRating: null,
};
const recipe2 = {
name: 'Chicken Curry',
ingredients: ['chicken breast', 'coconut milk', 'curry powder', 'onion', 'garlic'],
cookingTime: 42,
totalIngredients: null,
difficultyLevel: '',
ratings: [4, 5, 5, 5],
averageRating: null,
};
const recipe3 = {
name: 'Vegetable Stir Fry',
ingredients: ['broccoli', 'carrot', 'bell pepper'],
cookingTime: 15,
totalIngredients: null,
difficultyLevel: '',
ratings: [4, 3, 4, 5],
averageRating: null,
};
recipes.push(recipe1, recipe2, recipe3);
--fcc-editable-region--
--fcc-editable-region--
```
@@ -14,7 +14,7 @@ Create a `getTotalIngredients` function that takes a single argument, representi
You should create a `getTotalIngredients` function.
```js
assert.isFunction(getTotalIngredients)
assert.isFunction(getTotalIngredients);
```
Your `getTotalIngredients` function should have a single parameter.
@@ -26,7 +26,7 @@ assert.lengthOf(getTotalIngredients, 1);
Your `getTotalIngredients` function should return a number.
```js
assert.isNumber(getTotalIngredients(recipe1.ingredients))
assert.isNumber(getTotalIngredients(recipe1.ingredients));
```
`getTotalIngredients(recipe1.ingredients)` should return `4`.
@@ -55,42 +55,31 @@ assert.strictEqual(getTotalIngredients(recipe3.ingredients), 3);
const recipes = [];
const recipe1 = {
name: 'Spaghetti Carbonara',
ingredients: ['spaghetti', 'Parmesan cheese', 'pancetta', 'black pepper'],
name: "Spaghetti Carbonara",
ingredients: ["spaghetti", "Parmesan cheese", "pancetta", "black pepper"],
cookingTime: 22,
totalIngredients: null,
difficultyLevel: '',
ratings: [4, 5, 4, 5],
averageRating: null,
difficultyLevel: ""
};
const recipe2 = {
name: 'Chicken Curry',
ingredients: ['chicken breast', 'coconut milk', 'curry powder', 'onion', 'garlic'],
name: "Chicken Curry",
ingredients: ["chicken breast", "coconut milk", "curry powder", "onion", "garlic"],
cookingTime: 42,
totalIngredients: null,
difficultyLevel: '',
ratings: [4, 5, 5, 5],
averageRating: null,
difficultyLevel: ""
};
const recipe3 = {
name: 'Vegetable Stir Fry',
ingredients: ['broccoli', 'carrot', 'bell pepper'],
name: "Vegetable Stir Fry",
ingredients: ["broccoli", "carrot", "bell pepper"],
cookingTime: 15,
totalIngredients: null,
difficultyLevel: '',
ratings: [4, 3, 4, 5],
averageRating: null,
difficultyLevel: ""
};
recipes.push(recipe1, recipe2, recipe3);
function getAverageRating(ratings) {
const total = ratings[0] + ratings[1] + ratings[2] + ratings[3];
return total / ratings.length;
}
--fcc-editable-region--
--fcc-editable-region--
@@ -16,7 +16,7 @@ If the cooking time is less than or equal to `30`, the function should return `"
You should create a `getDifficultyLevel` function.
```js
assert.isFunction(getDifficultyLevel)
assert.isFunction(getDifficultyLevel);
```
Your `getDifficultyLevel` function should have a single parameter.
@@ -28,28 +28,28 @@ assert.lengthOf(getDifficultyLevel, 1);
Your `getDifficultyLevel` function should return `"easy"` when the cooking time is less than or equal to `30`.
```js
assert.strictEqual(getDifficultyLevel(10), "easy")
assert.strictEqual(getDifficultyLevel(20), "easy")
assert.strictEqual(getDifficultyLevel(29), "easy")
assert.strictEqual(getDifficultyLevel(30), "easy")
assert.strictEqual(getDifficultyLevel(10), "easy");
assert.strictEqual(getDifficultyLevel(20), "easy");
assert.strictEqual(getDifficultyLevel(29), "easy");
assert.strictEqual(getDifficultyLevel(30), "easy");
```
Your `getDifficultyLevel` function should return `"medium"` when the cooking time is greater than `31` and less than or equal to `60`.
```js
assert.strictEqual(getDifficultyLevel(31), "medium")
assert.strictEqual(getDifficultyLevel(40), "medium")
assert.strictEqual(getDifficultyLevel(50), "medium")
assert.strictEqual(getDifficultyLevel(60), "medium")
assert.strictEqual(getDifficultyLevel(31), "medium");
assert.strictEqual(getDifficultyLevel(40), "medium");
assert.strictEqual(getDifficultyLevel(50), "medium");
assert.strictEqual(getDifficultyLevel(60), "medium");
```
Your `getDifficultyLevel` function should return `"hard"` when the cooking time is greater than `60`.
```js
assert.strictEqual(getDifficultyLevel(61), "hard")
assert.strictEqual(getDifficultyLevel(65), "hard")
assert.strictEqual(getDifficultyLevel(70), "hard")
assert.strictEqual(getDifficultyLevel(75), "hard")
assert.strictEqual(getDifficultyLevel(61), "hard");
assert.strictEqual(getDifficultyLevel(65), "hard");
assert.strictEqual(getDifficultyLevel(70), "hard");
assert.strictEqual(getDifficultyLevel(75), "hard");
```
# --seed--
@@ -60,42 +60,31 @@ assert.strictEqual(getDifficultyLevel(75), "hard")
const recipes = [];
const recipe1 = {
name: 'Spaghetti Carbonara',
ingredients: ['spaghetti', 'Parmesan cheese', 'pancetta', 'black pepper'],
name: "Spaghetti Carbonara",
ingredients: ["spaghetti", "Parmesan cheese", "pancetta", "black pepper"],
cookingTime: 22,
totalIngredients: null,
difficultyLevel: '',
ratings: [4, 5, 4, 5],
averageRating: null,
difficultyLevel: ""
};
const recipe2 = {
name: 'Chicken Curry',
ingredients: ['chicken breast', 'coconut milk', 'curry powder', 'onion', 'garlic'],
name: "Chicken Curry",
ingredients: ["chicken breast", "coconut milk", "curry powder", "onion", "garlic"],
cookingTime: 42,
totalIngredients: null,
difficultyLevel: '',
ratings: [4, 5, 5, 5],
averageRating: null,
difficultyLevel: ""
};
const recipe3 = {
name: 'Vegetable Stir Fry',
ingredients: ['broccoli', 'carrot', 'bell pepper'],
name: "Vegetable Stir Fry",
ingredients: ["broccoli", "carrot", "bell pepper"],
cookingTime: 15,
totalIngredients: null,
difficultyLevel: '',
ratings: [4, 3, 4, 5],
averageRating: null,
difficultyLevel: ""
};
recipes.push(recipe1, recipe2, recipe3);
function getAverageRating(ratings) {
const total = ratings[0] + ratings[1] + ratings[2] + ratings[3];
return total / ratings.length;
}
function getTotalIngredients(ingredients) {
return ingredients.length;
}
@@ -9,34 +9,16 @@ dashedName: step-10
It's time to test each of the functions. You can use any of the recipes for this, but this tutorial will start with `recipe1`.
Create three new variables: `recipe1AverageRating`, `recipe1TotalIngredients`, and `recipe1DifficultyLevel`. Assign them the values by calling the corresponding function for each variable and passing in the appropriate `recipe1` property.
Create two new variables: `recipe1TotalIngredients` and `recipe1DifficultyLevel`. Assign them the values by calling the corresponding function for each variable and passing in the appropriate `recipe1` property.
Finally, log each variable to the console to see the results.
# --hints--
You should create a `recipe1AverageRating` variable.
```js
assert.isNotNull(recipe1AverageRating)
```
Your `recipe1AverageRating` variable should be set to `getAverageRating(recipe1.ratings)`.
```js
assert.equal(recipe1AverageRating, getAverageRating(recipe1.ratings));
```
You should log `recipe1AverageRating` to the console.
```js
assert.match(code, /console\.log\(recipe1AverageRating\);?/)
```
You should create a `recipe1TotalIngredients` variable.
```js
assert.isNotNull(recipe1TotalIngredients)
assert.isNotNull(recipe1TotalIngredients);
```
Your `recipe1TotalIngredients` variable should be set to `getTotalIngredients(recipe1.ingredients)`.
@@ -48,13 +30,13 @@ assert.equal(recipe1TotalIngredients, getTotalIngredients(recipe1.ingredients));
You should log `recipe1TotalIngredients` to the console.
```js
assert.match(code, /console\.log\(recipe1TotalIngredients\);?/)
assert.match(code, /console\.log\(recipe1TotalIngredients\);?/);
```
You should create a `recipe1DifficultyLevel` variable.
```js
assert.isNotNull(recipe1DifficultyLevel)
assert.isNotNull(recipe1DifficultyLevel);
```
Your `recipe1DifficultyLevel` variable should be set to `getDifficultyLevel(recipe1.cookingTime)`.
@@ -66,7 +48,7 @@ assert.equal(recipe1DifficultyLevel, getDifficultyLevel(recipe1.cookingTime));
You should log `recipe1DifficultyLevel` to the console.
```js
assert.match(code, /console\.log\(recipe1DifficultyLevel\);?/)
assert.match(code, /console\.log\(recipe1DifficultyLevel\);?/);
```
# --seed--
@@ -77,53 +59,42 @@ assert.match(code, /console\.log\(recipe1DifficultyLevel\);?/)
const recipes = [];
const recipe1 = {
name: 'Spaghetti Carbonara',
ingredients: ['spaghetti', 'Parmesan cheese', 'pancetta', 'black pepper'],
name: "Spaghetti Carbonara",
ingredients: ["spaghetti", "Parmesan cheese", "pancetta", "black pepper"],
cookingTime: 22,
totalIngredients: null,
difficultyLevel: '',
ratings: [4, 5, 4, 5],
averageRating: null,
difficultyLevel: ""
};
const recipe2 = {
name: 'Chicken Curry',
ingredients: ['chicken breast', 'coconut milk', 'curry powder', 'onion', 'garlic'],
name: "Chicken Curry",
ingredients: ["chicken breast", "coconut milk", "curry powder", "onion", "garlic"],
cookingTime: 42,
totalIngredients: null,
difficultyLevel: '',
ratings: [4, 5, 5, 5],
averageRating: null,
difficultyLevel: ""
};
const recipe3 = {
name: 'Vegetable Stir Fry',
ingredients: ['broccoli', 'carrot', 'bell pepper'],
name: "Vegetable Stir Fry",
ingredients: ["broccoli", "carrot", "bell pepper"],
cookingTime: 15,
totalIngredients: null,
difficultyLevel: '',
ratings: [4, 3, 4, 5],
averageRating: null,
difficultyLevel: ""
};
recipes.push(recipe1, recipe2, recipe3);
function getAverageRating(ratings) {
const total = ratings[0] + ratings[1] + ratings[2] + ratings[3];
return total / ratings.length;
}
function getTotalIngredients(ingredients) {
return ingredients.length;
}
function getDifficultyLevel(cookingTime) {
if (cookingTime <= 30) {
return 'easy';
return "easy";
} else if (cookingTime <= 60) {
return 'medium';
return "medium";
} else {
return 'hard';
return "hard";
}
}
@@ -7,24 +7,12 @@ dashedName: step-11
# --description--
You can now fill in each item of the `recipes` array with values for the `averageRating`, `totalIngredients`, and `difficultyLevel` properties.
You can now fill in each item of the `recipes` array with values for the `totalIngredients` and `difficultyLevel` properties.
For now, access the `averageRating`, `totalIngredients`, and `difficultyLevel` of `recipe1` and set them to the appropriate results of function calls and arguments.
For now, access the `totalIngredients` and `difficultyLevel` of `recipe1` and set them to the appropriate results of function calls and arguments.
# --hints--
You should access the `averageRating` property of `recipe1`.
```js
assert.isNotNull(recipe1.averageRating);
```
You should assign the result of calling `getAverageRating` with `recipe1.ratings` to the `averageRating` property of `recipe1`.
```js
assert.strictEqual(recipe1.averageRating, getAverageRating(recipe1.ratings));
```
You should access the `totalIngredients` property of `recipe1`.
```js
@@ -57,59 +45,45 @@ assert.strictEqual(recipe1.difficultyLevel, getDifficultyLevel(recipe1.cookingTi
const recipes = [];
const recipe1 = {
name: 'Spaghetti Carbonara',
ingredients: ['spaghetti', 'Parmesan cheese', 'pancetta', 'black pepper'],
name: "Spaghetti Carbonara",
ingredients: ["spaghetti", "Parmesan cheese", "pancetta", "black pepper"],
cookingTime: 22,
totalIngredients: null,
difficultyLevel: '',
ratings: [4, 5, 4, 5],
averageRating: null,
difficultyLevel: ""
};
const recipe2 = {
name: 'Chicken Curry',
ingredients: ['chicken breast', 'coconut milk', 'curry powder', 'onion', 'garlic'],
name: "Chicken Curry",
ingredients: ["chicken breast", "coconut milk", "curry powder", "onion", "garlic"],
cookingTime: 42,
totalIngredients: null,
difficultyLevel: '',
ratings: [4, 5, 5, 5],
averageRating: null,
difficultyLevel: ""
};
const recipe3 = {
name: 'Vegetable Stir Fry',
ingredients: ['broccoli', 'carrot', 'bell pepper'],
name: "Vegetable Stir Fry",
ingredients: ["broccoli", "carrot", "bell pepper"],
cookingTime: 15,
totalIngredients: null,
difficultyLevel: '',
ratings: [4, 3, 4, 5],
averageRating: null,
difficultyLevel: ""
};
recipes.push(recipe1, recipe2, recipe3);
function getAverageRating(ratings) {
const total = ratings[0] + ratings[1] + ratings[2] + ratings[3];
return total / ratings.length;
}
function getTotalIngredients(ingredients) {
return ingredients.length;
}
function getDifficultyLevel(cookingTime) {
if (cookingTime <= 30) {
return 'easy';
return "easy";
} else if (cookingTime <= 60) {
return 'medium';
return "medium";
} else {
return 'hard';
return "hard";
}
}
const recipe1AverageRating = getAverageRating(recipe1.ratings);
console.log(recipe1AverageRating);
const recipe1TotalIngredients = getTotalIngredients(recipe1.ingredients);
console.log(recipe1TotalIngredients);
@@ -7,22 +7,10 @@ dashedName: step-12
# --description--
Repeat the process for the `averageRating`, `totalIngredients`, and `difficultyLevel` properties of `recipe2`.
Repeat the process for the `totalIngredients` and `difficultyLevel` properties of `recipe2` and `recipe3`.
# --hints--
You should access the `averageRating` property of `recipe2`.
```js
assert.isNotNull(recipe2.averageRating);
```
You should assign the result of calling `getAverageRating` with `recipe2.ratings` to the `averageRating` property of `recipe2`.
```js
assert.strictEqual(recipe2.averageRating, getAverageRating(recipe2.ratings));
```
You should access the `totalIngredients` property of `recipe2`.
```js
@@ -47,6 +35,30 @@ You should assign the result of calling `getDifficultyLevel` with `recipe2.cooki
assert.strictEqual(recipe2.difficultyLevel, getDifficultyLevel(recipe2.cookingTime));
```
You should access the `totalIngredients` property of `recipe3`.
```js
assert.isNotNull(recipe3.totalIngredients);
```
You should assign the result of calling `getTotalIngredients` with `recipe3.ingredients` to the `totalIngredients` property of `recipe3`.
```js
assert.strictEqual(recipe3.totalIngredients, getTotalIngredients(recipe3.ingredients));
```
You should access the `difficultyLevel` property of `recipe3`.
```js
assert.isNotEmpty(recipe3.difficultyLevel);
```
You should assign the result of calling `getDifficultyLevel` with `recipe3.cookingTime` to the `difficultyLevel` property of `recipe3`.
```js
assert.strictEqual(recipe3.difficultyLevel, getDifficultyLevel(recipe3.cookingTime));
```
# --seed--
## --seed-contents--
@@ -55,68 +67,53 @@ assert.strictEqual(recipe2.difficultyLevel, getDifficultyLevel(recipe2.cookingTi
const recipes = [];
const recipe1 = {
name: 'Spaghetti Carbonara',
ingredients: ['spaghetti', 'Parmesan cheese', 'pancetta', 'black pepper'],
name: "Spaghetti Carbonara",
ingredients: ["spaghetti", "Parmesan cheese", "pancetta", "black pepper"],
cookingTime: 22,
totalIngredients: null,
difficultyLevel: '',
ratings: [4, 5, 4, 5],
averageRating: null,
difficultyLevel: ""
};
const recipe2 = {
name: 'Chicken Curry',
ingredients: ['chicken breast', 'coconut milk', 'curry powder', 'onion', 'garlic'],
name: "Chicken Curry",
ingredients: ["chicken breast", "coconut milk", "curry powder", "onion", "garlic"],
cookingTime: 42,
totalIngredients: null,
difficultyLevel: '',
ratings: [4, 5, 5, 5],
averageRating: null,
difficultyLevel: ""
};
const recipe3 = {
name: 'Vegetable Stir Fry',
ingredients: ['broccoli', 'carrot', 'bell pepper'],
name: "Vegetable Stir Fry",
ingredients: ["broccoli", "carrot", "bell pepper"],
cookingTime: 15,
totalIngredients: null,
difficultyLevel: '',
ratings: [4, 3, 4, 5],
averageRating: null,
difficultyLevel: ""
};
recipes.push(recipe1, recipe2, recipe3);
function getAverageRating(ratings) {
const total = ratings[0] + ratings[1] + ratings[2] + ratings[3];
return total / ratings.length;
}
function getTotalIngredients(ingredients) {
return ingredients.length;
}
function getDifficultyLevel(cookingTime) {
if (cookingTime <= 30) {
return 'easy';
return "easy";
} else if (cookingTime <= 60) {
return 'medium';
return "medium";
} else {
return 'hard';
return "hard";
}
}
const recipe1AverageRating = getAverageRating(recipe1.ratings);
console.log(recipe1AverageRating);
const recipe1TotalIngredients = getTotalIngredients(recipe1.ingredients);
console.log(recipe1TotalIngredients);
const recipe1DifficultyLevel = getDifficultyLevel(recipe1.cookingTime);
console.log(recipe1DifficultyLevel);
recipe1.averageRating = getAverageRating(recipe1.ratings);
recipe1.totalIngredients = getTotalIngredients(recipe1.ingredients)
recipe1.difficultyLevel = getDifficultyLevel(recipe1.cookingTime)
recipe1.totalIngredients = getTotalIngredients(recipe1.ingredients);
recipe1.difficultyLevel = getDifficultyLevel(recipe1.cookingTime);
--fcc-editable-region--
@@ -7,8 +7,6 @@ dashedName: step-13
# --description--
The `averageRating`, `totalIngredients`, and `difficultyLevel` properties of `recipe3` have been filled in for you.
Now, log the `recipes` array to the console to see all its items filled with the updated values.
With that, your recipes tracker project is complete.
@@ -18,7 +16,7 @@ With that, your recipes tracker project is complete.
You should log the `recipes` array to the console.
```js
assert.match(code, /console\.log\(recipes\);?/)
assert.match(code, /console\.log\(recipes\);?/);
```
# --seed--
@@ -29,76 +27,59 @@ assert.match(code, /console\.log\(recipes\);?/)
const recipes = [];
const recipe1 = {
name: 'Spaghetti Carbonara',
ingredients: ['spaghetti', 'Parmesan cheese', 'pancetta', 'black pepper'],
name: "Spaghetti Carbonara",
ingredients: ["spaghetti", "Parmesan cheese", "pancetta", "black pepper"],
cookingTime: 22,
totalIngredients: null,
difficultyLevel: '',
ratings: [4, 5, 4, 5],
averageRating: null,
difficultyLevel: ""
};
const recipe2 = {
name: 'Chicken Curry',
ingredients: ['chicken breast', 'coconut milk', 'curry powder', 'onion', 'garlic'],
name: "Chicken Curry",
ingredients: ["chicken breast", "coconut milk", "curry powder", "onion", "garlic"],
cookingTime: 42,
totalIngredients: null,
difficultyLevel: '',
ratings: [4, 5, 5, 5],
averageRating: null,
difficultyLevel: ""
};
const recipe3 = {
name: 'Vegetable Stir Fry',
ingredients: ['broccoli', 'carrot', 'bell pepper'],
name: "Vegetable Stir Fry",
ingredients: ["broccoli", "carrot", "bell pepper"],
cookingTime: 15,
totalIngredients: null,
difficultyLevel: '',
ratings: [4, 3, 4, 5],
averageRating: null,
difficultyLevel: ""
};
recipes.push(recipe1, recipe2, recipe3);
function getAverageRating(ratings) {
const total = ratings[0] + ratings[1] + ratings[2] + ratings[3];
return total / ratings.length;
}
function getTotalIngredients(ingredients) {
return ingredients.length;
}
function getDifficultyLevel(cookingTime) {
if (cookingTime <= 30) {
return 'easy';
return "easy";
} else if (cookingTime <= 60) {
return 'medium';
return "medium";
} else {
return 'hard';
return "hard";
}
}
const recipe1AverageRating = getAverageRating(recipe1.ratings);
console.log(recipe1AverageRating);
const recipe1TotalIngredients = getTotalIngredients(recipe1.ingredients);
console.log(recipe1TotalIngredients);
const recipe1DifficultyLevel = getDifficultyLevel(recipe1.cookingTime);
console.log(recipe1DifficultyLevel);
recipe1.averageRating = getAverageRating(recipe1.ratings);
recipe1.totalIngredients = getTotalIngredients(recipe1.ingredients)
recipe1.difficultyLevel = getDifficultyLevel(recipe1.cookingTime)
recipe1.totalIngredients = getTotalIngredients(recipe1.ingredients);
recipe1.difficultyLevel = getDifficultyLevel(recipe1.cookingTime);
recipe2.averageRating = getAverageRating(recipe2.ratings);
recipe2.totalIngredients = getTotalIngredients(recipe2.ingredients);
recipe2.difficultyLevel = getDifficultyLevel(recipe2.cookingTime);
recipe3.averageRating = getAverageRating(recipe3.ratings);
recipe3.totalIngredients = getTotalIngredients(recipe3.ingredients)
recipe3.difficultyLevel = getDifficultyLevel(recipe3.cookingTime)
recipe3.totalIngredients = getTotalIngredients(recipe3.ingredients);
recipe3.difficultyLevel = getDifficultyLevel(recipe3.cookingTime);
--fcc-editable-region--
@@ -111,76 +92,59 @@ recipe3.difficultyLevel = getDifficultyLevel(recipe3.cookingTime)
const recipes = [];
const recipe1 = {
name: 'Spaghetti Carbonara',
ingredients: ['spaghetti', 'Parmesan cheese', 'pancetta', 'black pepper'],
name: "Spaghetti Carbonara",
ingredients: ["spaghetti", "Parmesan cheese", "pancetta", "black pepper"],
cookingTime: 22,
totalIngredients: null,
difficultyLevel: '',
ratings: [4, 5, 4, 5],
averageRating: null,
difficultyLevel: ""
};
const recipe2 = {
name: 'Chicken Curry',
ingredients: ['chicken breast', 'coconut milk', 'curry powder', 'onion', 'garlic'],
name: "Chicken Curry",
ingredients: ["chicken breast", "coconut milk", "curry powder", "onion", "garlic"],
cookingTime: 42,
totalIngredients: null,
difficultyLevel: '',
ratings: [4, 5, 5, 5],
averageRating: null,
difficultyLevel: ""
};
const recipe3 = {
name: 'Vegetable Stir Fry',
ingredients: ['broccoli', 'carrot', 'bell pepper'],
name: "Vegetable Stir Fry",
ingredients: ["broccoli", "carrot", "bell pepper"],
cookingTime: 15,
totalIngredients: null,
difficultyLevel: '',
ratings: [4, 3, 4, 5],
averageRating: null,
difficultyLevel: ""
};
recipes.push(recipe1, recipe2, recipe3);
function getAverageRating(ratings) {
const total = ratings[0] + ratings[1] + ratings[2] + ratings[3];
return total / ratings.length;
}
function getTotalIngredients(ingredients) {
return ingredients.length;
}
function getDifficultyLevel(cookingTime) {
if (cookingTime <= 30) {
return 'easy';
return "easy";
} else if (cookingTime <= 60) {
return 'medium';
return "medium";
} else {
return 'hard';
return "hard";
}
}
const recipe1AverageRating = getAverageRating(recipe1.ratings);
console.log(`Recipe 1 Average Rating ${recipe1AverageRating}`);
const recipe1TotalIngredients = getTotalIngredients(recipe1.ingredients);
console.log(`Recipe 1 Total Ingredients: ${recipe1TotalIngredients}`);
console.log(recipe1TotalIngredients);
const recipe1DifficultyLevel = getDifficultyLevel(recipe1.cookingTime);
console.log(`Recipe 1 Difficulty: ${recipe1DifficultyLevel}`);
console.log(recipe1DifficultyLevel);
recipe1.averageRating = getAverageRating(recipe1.ratings);
recipe1.totalIngredients = getTotalIngredients(recipe1.ingredients)
recipe1.difficultyLevel = getDifficultyLevel(recipe1.cookingTime)
recipe1.totalIngredients = getTotalIngredients(recipe1.ingredients);
recipe1.difficultyLevel = getDifficultyLevel(recipe1.cookingTime);
recipe2.averageRating = getAverageRating(recipe2.ratings);
recipe2.totalIngredients = getTotalIngredients(recipe2.ingredients);
recipe2.difficultyLevel = getDifficultyLevel(recipe2.cookingTime);
recipe3.averageRating = getAverageRating(recipe3.ratings);
recipe3.totalIngredients = getTotalIngredients(recipe3.ingredients)
recipe3.difficultyLevel = getDifficultyLevel(recipe3.cookingTime)
recipe3.totalIngredients = getTotalIngredients(recipe3.ingredients);
recipe3.difficultyLevel = getDifficultyLevel(recipe3.cookingTime);
console.log(recipes);
```
@@ -14,7 +14,6 @@ Add the following properties to the `recipe1` object:
|`cookingTime`|`22`|
|`totalIngredients`|`null`|
|`difficultyLevel`|`""`|
|`averageRating`|`null`|
The properties with `null` and empty string values will be updated later after you calculate them.
@@ -56,18 +55,6 @@ Your `difficultyLevel` property should be set to an empty string.
assert.deepEqual(recipe1.difficultyLevel, "");
```
Your `recipe1` object should have a `averageRating` property.
```js
assert.property(recipe1, "averageRating");
```
Your `averageRating` property should be set to `null`.
```js
assert.isNull(recipe1.averageRating);
```
# --seed--
## --seed-contents--
@@ -76,9 +63,8 @@ assert.isNull(recipe1.averageRating);
const recipes = [];
const recipe1 = {
name: 'Spaghetti Carbonara',
ingredients: ['spaghetti', 'Parmesan cheese', 'pancetta', 'black pepper'],
ratings: [4, 5, 4, 5],
name: "Spaghetti Carbonara",
ingredients: ["spaghetti", "Parmesan cheese", "pancetta", "black pepper"],
--fcc-editable-region--
--fcc-editable-region--
@@ -1,8 +1,8 @@
---
id: 670e4f45f7116c0f216a5177
title: Step 5
title: Step 6
challengeType: 1
dashedName: step-5
dashedName: step-6
---
# --description--
@@ -13,18 +13,20 @@ You can use either dot (`.`) or bracket (`[]`) notation to do this. Here's an ex
```js
const person = {
name: 'John',
name: "John",
age: 30,
job: 'Software Engineer'
job: "Software Engineer"
};
console.log(person.name); // John
console.log(person['age']); // 30
```
Access the `name` properties of both `recipe1` and `recipe2`, and assign them to the variables `recipe1Name` and `recipe2Name`, respectively.
Access the `name` property of `recipe1`, and assign it to the variable `recipe1Name`.
Next, access the `cookingTime` properties of both recipes and assign them to the variables `recipe1CookingTime` and `recipe2CookingTime`, respectively.
Next, access the `cookingTime` property of `recipe2` and assign it to the variable `recipe2CookingTime`.
Finialy, access the `ingredients` property of `recipe3` and assign it to the variable `recipe3Ingredients`.
Make sure all the variables you created are logged to the console.
@@ -48,42 +50,6 @@ You should log `recipe1Name` to the console.
assert.match(code, /console\.log\(\s*recipe1Name\s*\)/);
```
You should create a `recipe2Name` variable.
```js
assert.isDefined(recipe2Name);
```
You should assign the value of the `name` property of `recipe2` to your `recipe2name` variable.
```js
assert.strictEqual(recipe2Name, recipe2.name);
```
You should log `recipe2Name` to the console.
```js
assert.match(code, /console\.log\(recipe2Name\)/);
```
You should create a `recipe1CookingTime` variable.
```js
assert.isDefined(recipe1CookingTime);
```
You should assign the value of the `cookingTime` property of `recipe1` to your `recipe1CookingTime` variable.
```js
assert.strictEqual(recipe1CookingTime, recipe1.cookingTime);
```
You should log `recipe1CookingTime` to the console.
```js
assert.match(code, /console\.log\(recipe1CookingTime\)/);
```
You should create a `recipe2CookingTime` variable.
```js
@@ -102,6 +68,24 @@ You should log `recipe2CookingTime` to the console.
assert.match(code, /console\.log\(recipe2CookingTime\)/);
```
You sould create a `recipe3Ingredients` variable.
```js
assert.isDefined(recipe3Ingredients);
```
You should assign the value of the `ingredients` property of `recipe3` to your `recipe3Ingredients` variable.
```js
assert.strictEqual(recipe3Ingredients, recipe3.ingredients);
```
You should log `recipe3Ingredients` to the console.
```js
assert.match(code, /console\.log\(recipe3Ingredients\)/);
```
# --seed--
## --seed-contents--
@@ -110,23 +94,27 @@ assert.match(code, /console\.log\(recipe2CookingTime\)/);
const recipes = [];
const recipe1 = {
name: 'Spaghetti Carbonara',
ingredients: ['spaghetti', 'Parmesan cheese', 'pancetta', 'black pepper'],
name: "Spaghetti Carbonara",
ingredients: ["spaghetti", "Parmesan cheese", "pancetta", "black pepper"],
cookingTime: 22,
totalIngredients: null,
difficultyLevel: '',
ratings: [4, 5, 4, 5],
averageRating: null,
difficultyLevel: ""
};
const recipe2 = {
name: 'Chicken Curry',
ingredients: ['chicken breast', 'coconut milk', 'curry powder', 'onion', 'garlic'],
name: "Chicken Curry",
ingredients: ["chicken breast", "coconut milk", "curry powder", "onion", "garlic"],
cookingTime: 42,
totalIngredients: null,
difficultyLevel: '',
ratings: [4, 5, 5, 5],
averageRating: null,
difficultyLevel: ""
};
const recipe3 = {
name: "Vegetable Stir Fry",
ingredients: ["broccoli", "carrot", "bell pepper"],
cookingTime: 15,
totalIngredients: null,
difficultyLevel: ""
};
--fcc-editable-region--
@@ -0,0 +1,126 @@
---
id: 69161f4c0c9c8c48b3c843c5
title: Step 5
challengeType: 1
dashedName: step-5
---
# --description--
Create a `recipe3` object with the following properties and values:
|Key|Value|
|-----------|-------|
|`name`|`Vegetable Stir Fry`|
|`ingredients`|`["broccoli", "carrot", "bell pepper"]`|
|`cookingTime`|`15`|
|`totalIngredients`|`null`|
|`difficultyLevel`|`""`|
# --hints--
You should create an object named `recipe3`.
```js
assert.isObject(recipe3);
```
Your `recipe3` object should have a `name` property.
```js
assert.property(recipe3, "name");
```
Your `name` property should be set to `Vegetable Stir Fry`.
```js
assert.equal(recipe3.name, "Vegetable Stir Fry");
```
Your `recipe3` object should have an `ingredients` property.
```js
assert.property(recipe3, "ingredients");
```
Your `ingredients` property should have an array value.
```js
assert.isArray(recipe3.ingredients);
```
The array value of your `ingredients` property should have `broccoli`, `carrot` and `bell pepper` in it.
```js
assert.deepEqual(recipe3.ingredients, ["broccoli", "carrot", "bell pepper"]);
```
Your `recipe3` object should have a `cookingTime` property.
```js
assert.property(recipe3, "cookingTime");
```
Your `cookingTime` property value should be a number.
```js
assert.isNumber(recipe3.cookingTime);
```
Your `cookingTime` property should be set to `15`.
```js
assert.equal(recipe3.cookingTime, 15);
```
Your `recipe3` object should have a `totalIngredients` property.
```js
assert.property(recipe3, "totalIngredients");
```
Your `totalIngredients` property should be set to `null`.
```js
assert.isNull(recipe3.totalIngredients);
```
Your `recipe3` object should have a `difficultyLevel` property.
```js
assert.property(recipe3, "difficultyLevel");
```
Your `difficultyLevel` property should be set to an empty string.
```js
assert.deepEqual(recipe3.difficultyLevel, "");
```
# --seed--
## --seed-contents--
```js
const recipes = [];
const recipe1 = {
name: "Spaghetti Carbonara",
ingredients: ["spaghetti", "Parmesan cheese", "pancetta", "black pepper"],
cookingTime: 22,
totalIngredients: null,
difficultyLevel: ""
};
const recipe2 = {
name: "Chicken Curry",
ingredients: ["chicken breast", "coconut milk", "curry powder", "onion", "garlic"],
cookingTime: 42,
totalIngredients: null,
difficultyLevel: ""
};
--fcc-editable-region--
--fcc-editable-region--
```
@@ -6,58 +6,19 @@
"hasEditableBoundaries": true,
"dashedName": "workshop-recipe-tracker",
"challengeOrder": [
{
"id": "66fbcdfed6848e48947dbbc9",
"title": "Step 1"
},
{
"id": "66fbcf750a62784cf11f562d",
"title": "Step 2"
},
{
"id": "66ff02792b3042a2b811f475",
"title": "Step 3"
},
{
"id": "66fbcf750a62784cf11f562e",
"title": "Step 4"
},
{
"id": "670e4f45f7116c0f216a5177",
"title": "Step 5"
},
{
"id": "66fbcf750a62784cf11f5630",
"title": "Step 6"
},
{
"id": "66fbcf750a62784cf11f5631",
"title": "Step 7"
},
{
"id": "66fbcf750a62784cf11f5632",
"title": "Step 8"
},
{
"id": "66fbcf750a62784cf11f5633",
"title": "Step 9"
},
{
"id": "66fbcf750a62784cf11f5634",
"title": "Step 10"
},
{
"id": "66fbcf750a62784cf11f5635",
"title": "Step 11"
},
{
"id": "66fbcf750a62784cf11f5636",
"title": "Step 12"
},
{
"id": "66fbcf750a62784cf11f5637",
"title": "Step 13"
}
{ "id": "66fbcdfed6848e48947dbbc9", "title": "Step 1" },
{ "id": "66fbcf750a62784cf11f562d", "title": "Step 2" },
{ "id": "66ff02792b3042a2b811f475", "title": "Step 3" },
{ "id": "66fbcf750a62784cf11f562e", "title": "Step 4" },
{ "id": "69161f4c0c9c8c48b3c843c5", "title": "Step 5" },
{ "id": "670e4f45f7116c0f216a5177", "title": "Step 6" },
{ "id": "66fbcf750a62784cf11f5630", "title": "Step 7" },
{ "id": "66fbcf750a62784cf11f5632", "title": "Step 8" },
{ "id": "66fbcf750a62784cf11f5633", "title": "Step 9" },
{ "id": "66fbcf750a62784cf11f5634", "title": "Step 10" },
{ "id": "66fbcf750a62784cf11f5635", "title": "Step 11" },
{ "id": "66fbcf750a62784cf11f5636", "title": "Step 12" },
{ "id": "66fbcf750a62784cf11f5637", "title": "Step 13" }
],
"helpCategory": "JavaScript",
"blockLabel": "workshop"