fix(curriculum): update getShoppingListMsg function to accept an array parameter (#59253)

This commit is contained in:
Kinjalk Bajpai
2025-04-07 21:17:03 +05:30
committed by GitHub
parent d5b1237375
commit c3523cfe62
16 changed files with 120 additions and 111 deletions

View File

@@ -11,7 +11,7 @@ To see the updated shopping list, you will need to log the current shopping list
Since this message will be used repeatedly throughout the workshop, it is best to create a reusable function.
Create a function called `getShoppingListMsg` that returns the string `"Current Shopping List: "` followed by the `shoppingList` array.
Create a function called `getShoppingListMsg` that takes an array as a parameter and returns the string `"Current Shopping List: "` followed by the contents of the provided array.
You can use template literals or string concatenation with the `+` operator to combine the string and the `shoppingList` array.
@@ -26,13 +26,20 @@ assert.isFunction(getShoppingListMsg);
Your `getShoppingListMsg` function should return a string.
```js
assert.isString(getShoppingListMsg());
assert.isString(getShoppingListMsg(shoppingList));
```
Your `getShoppingListMsg` function should return the message of `"Current Shopping List: "` followed by the `shoppingList` array. Double check spacing and spelling errors.
Your `getShoppingListMsg` function should accept an array as an argument.
```js
assert.strictEqual(getShoppingListMsg(), "Current Shopping List: Apples");
assert.strictEqual(getShoppingListMsg(["Anchovies", "Olives"]), "Current Shopping List: Anchovies,Olives");
```
Your `getShoppingListMsg` function should accept an array and return the message `"Current Shopping List: "` followed by the contents of that array. Double check spacing and spelling errors.
```js
assert.strictEqual(getShoppingListMsg(["Apples"]), "Current Shopping List: Apples");
```
# --seed--

View File

@@ -27,10 +27,10 @@ Your `shoppingList` array should contain the string `"Grapes"`.
assert.equal(shoppingList[1], "Grapes");
```
You should call the `getShoppingListMsg` function inside of the `console.log`.
You should call `getShoppingListMsg(shoppingList)` function inside of the `console.log`.
```js
assert.lengthOf(code.match(/console\.log\(\s*getShoppingListMsg\(\)\s*\)/g), 2);
assert.lengthOf(code.match(/console\.log\(\s*getShoppingListMsg\(\s*shoppingList\s*\)\s*\)/g), 2);
```
# --seed--
@@ -46,11 +46,11 @@ console.log("It will be nice to have some fruit to eat.");
shoppingList.push("Apples");
function getShoppingListMsg() {
return `Current Shopping List: ${shoppingList}`;
function getShoppingListMsg(arr) {
return `Current Shopping List: ${arr}`;
}
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
--fcc-editable-region--

View File

@@ -32,14 +32,14 @@ console.log("It will be nice to have some fruit to eat.");
shoppingList.push("Apples");
function getShoppingListMsg() {
return `Current Shopping List: ${shoppingList}`;
function getShoppingListMsg(arr) {
return `Current Shopping List: ${arr}`;
}
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
shoppingList.push("Grapes");
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
--fcc-editable-region--

View File

@@ -43,14 +43,14 @@ const shoppingList = [];
console.log("It will be nice to have some fruit to eat.");
shoppingList.push("Apples");
function getShoppingListMsg() {
return `Current Shopping List: ${shoppingList}`;
function getShoppingListMsg(arr) {
return `Current Shopping List: ${arr}`;
}
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
shoppingList.push("Grapes");
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
console.log("It looks like we need to get some cooking oil.");

View File

@@ -11,10 +11,10 @@ Next, add a `console.log` and call the `getShoppingListMsg` function inside of t
# --hints--
You should call the `getShoppingListMsg` function inside of the `console.log`.
You should call `getShoppingListMsg(shoppingList)` inside of the `console.log`.
```js
assert.lengthOf(code.match(/console\.log\(\s*getShoppingListMsg\(\)\s*\)/g), 3);
assert.lengthOf(code.match(/console\.log\(\s*getShoppingListMsg\(\s*shoppingList\s*\)\s*\)/g), 3);
```
# --seed--
@@ -30,14 +30,14 @@ console.log("It will be nice to have some fruit to eat.");
shoppingList.push("Apples");
function getShoppingListMsg() {
return `Current Shopping List: ${shoppingList}`;
function getShoppingListMsg(arr) {
return `Current Shopping List: ${arr}`;
}
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
shoppingList.push("Grapes");
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
console.log("It looks like we need to get some cooking oil.");

View File

@@ -58,19 +58,19 @@ console.log("It will be nice to have some fruit to eat.");
shoppingList.push("Apples");
function getShoppingListMsg() {
return `Current Shopping List: ${shoppingList}`;
function getShoppingListMsg(arr) {
return `Current Shopping List: ${arr}`;
}
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
shoppingList.push("Grapes");
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
console.log("It looks like we need to get some cooking oil.");
shoppingList.unshift("Vegetable Oil");
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
--fcc-editable-region--

View File

@@ -13,10 +13,10 @@ Add another `console.log` and call the `getShoppingListMsg` function inside of t
# --hints--
You should call the `getShoppingListMsg` function inside of the `console.log`.
You should call `getShoppingListMsg(shoppingList)` inside of the `console.log`.
```js
assert.lengthOf(code.match(/console\.log\(\s*getShoppingListMsg\(\)\s*\)/g), 4);
assert.lengthOf(code.match(/console\.log\(\s*getShoppingListMsg\(\s*shoppingList\s*\)\s*\)/g), 4);
```
# --seed--
@@ -32,19 +32,19 @@ console.log("It will be nice to have some fruit to eat.");
shoppingList.push("Apples");
function getShoppingListMsg() {
return `Current Shopping List: ${shoppingList}`;
function getShoppingListMsg(arr) {
return `Current Shopping List: ${arr}`;
}
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
shoppingList.push("Grapes");
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
console.log("It looks like we need to get some cooking oil.");
shoppingList.unshift("Vegetable Oil");
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
shoppingList.push("Popcorn", "Beef Jerky", "Potato Chips");

View File

@@ -32,22 +32,22 @@ console.log("It will be nice to have some fruit to eat.");
shoppingList.push("Apples");
function getShoppingListMsg() {
return `Current Shopping List: ${shoppingList}`;
function getShoppingListMsg(arr) {
return `Current Shopping List: ${arr}`;
}
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
shoppingList.push("Grapes");
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
console.log("It looks like we need to get some cooking oil.");
shoppingList.unshift("Vegetable Oil");
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
shoppingList.push("Popcorn", "Beef Jerky", "Potato Chips");
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
--fcc-editable-region--

View File

@@ -48,22 +48,22 @@ console.log("It will be nice to have some fruit to eat.");
shoppingList.push("Apples");
function getShoppingListMsg() {
return `Current Shopping List: ${shoppingList}`;
function getShoppingListMsg(arr) {
return `Current Shopping List: ${arr}`;
}
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
shoppingList.push("Grapes");
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
console.log("It looks like we need to get some cooking oil.");
shoppingList.unshift("Vegetable Oil");
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
shoppingList.push("Popcorn", "Beef Jerky", "Potato Chips");
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
console.log("This looks like too much junk food.");

View File

@@ -13,10 +13,10 @@ Add a `console.log` and call the `getShoppingListMsg` function inside of the `co
# --hints--
You should call the `getShoppingListMsg` function inside of the `console.log`.
You should call `getShoppingListMsg(shoppingList)` inside of the `console.log`.
```js
assert.lengthOf(code.match(/console\.log\(\s*getShoppingListMsg\(\)\s*\)/g), 5);
assert.lengthOf(code.match(/console\.log\(\s*getShoppingListMsg\(\s*shoppingList\s*\)\s*\)/g), 5);
```
# --seed--
@@ -32,22 +32,22 @@ console.log("It will be nice to have some fruit to eat.");
shoppingList.push("Apples");
function getShoppingListMsg() {
return `Current Shopping List: ${shoppingList}`;
function getShoppingListMsg(arr) {
return `Current Shopping List: ${arr}`;
}
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
shoppingList.push("Grapes");
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
console.log("It looks like we need to get some cooking oil.");
shoppingList.unshift("Vegetable Oil");
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
shoppingList.push("Popcorn", "Beef Jerky", "Potato Chips");
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
console.log("This looks like too much junk food.");

View File

@@ -35,10 +35,10 @@ You should use the `unshift` method to add the string `"Chocolate Cake"` to the
assert.strictEqual(shoppingList[0], "Chocolate Cake");
```
You should call the `getShoppingListMsg` function inside of the `console.log`.
You should call `getShoppingListMsg(shoppingList)` inside of the `console.log`.
```js
assert.lengthOf(code.match(/console\.log\(\s*getShoppingListMsg\(\)\s*\)/g), 6);
assert.lengthOf(code.match(/console\.log\(\s*getShoppingListMsg\(\s*shoppingList\s*\)\s*\)/g), 6);
```
# --seed--
@@ -54,27 +54,27 @@ console.log("It will be nice to have some fruit to eat.");
shoppingList.push("Apples");
function getShoppingListMsg() {
return `Current Shopping List: ${shoppingList}`;
function getShoppingListMsg(arr) {
return `Current Shopping List: ${arr}`;
}
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
shoppingList.push("Grapes");
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
console.log("It looks like we need to get some cooking oil.");
shoppingList.unshift("Vegetable Oil");
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
shoppingList.push("Popcorn", "Beef Jerky", "Potato Chips");
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
console.log("This looks like too much junk food.");
shoppingList.pop();
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
--fcc-editable-region--

View File

@@ -32,32 +32,32 @@ console.log("It will be nice to have some fruit to eat.");
shoppingList.push("Apples");
function getShoppingListMsg() {
return `Current Shopping List: ${shoppingList}`;
function getShoppingListMsg(arr) {
return `Current Shopping List: ${arr}`;
}
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
shoppingList.push("Grapes");
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
console.log("It looks like we need to get some cooking oil.");
shoppingList.unshift("Vegetable Oil");
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
shoppingList.push("Popcorn", "Beef Jerky", "Potato Chips");
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
console.log("This looks like too much junk food.");
shoppingList.pop();
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
console.log("It might be nice to get a dessert.");
shoppingList.unshift("Chocolate Cake");
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
--fcc-editable-region--

View File

@@ -48,32 +48,32 @@ console.log("It will be nice to have some fruit to eat.");
shoppingList.push("Apples");
function getShoppingListMsg() {
return `Current Shopping List: ${shoppingList}`;
function getShoppingListMsg(arr) {
return `Current Shopping List: ${arr}`;
}
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
shoppingList.push("Grapes");
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
console.log("It looks like we need to get some cooking oil.");
shoppingList.unshift("Vegetable Oil");
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
shoppingList.push("Popcorn", "Beef Jerky", "Potato Chips");
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
console.log("This looks like too much junk food.");
shoppingList.pop();
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
console.log("It might be nice to get a dessert.");
shoppingList.unshift("Chocolate Cake");
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
console.log("On second thought, maybe we should be more health conscious.");

View File

@@ -45,32 +45,32 @@ console.log("It will be nice to have some fruit to eat.");
shoppingList.push("Apples");
function getShoppingListMsg() {
return `Current Shopping List: ${shoppingList}`;
function getShoppingListMsg(arr) {
return `Current Shopping List: ${arr}`;
}
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
shoppingList.push("Grapes");
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
console.log("It looks like we need to get some cooking oil.");
shoppingList.unshift("Vegetable Oil");
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
shoppingList.push("Popcorn", "Beef Jerky", "Potato Chips");
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
console.log("This looks like too much junk food.");
shoppingList.pop();
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
console.log("It might be nice to get a dessert.");
shoppingList.unshift("Chocolate Cake");
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
console.log("On second thought, maybe we should be more health conscious.");

View File

@@ -9,14 +9,16 @@ dashedName: step-20
In this final step of the workshop, log the final grocery list to the console.
To do this, call the `getShoppingListMsg` function with the `shoppingList` array as an argument inside `console.log`.
And with this last step your grocery list is complete!
# --hints--
You should call the `getShoppingListMsg` function inside of the `console.log`.
You should call `getShoppingListMsg(shoppingList)` inside of the `console.log`.
```js
assert.lengthOf(code.match(/console\.log\(\s*getShoppingListMsg\(\)\s*\)/g), 7);
assert.lengthOf(code.match(/console\.log\(\s*getShoppingListMsg\(\s*shoppingList\s*\)\s*\)/g), 7);
```
# --seed--
@@ -32,32 +34,32 @@ console.log("It will be nice to have some fruit to eat.");
shoppingList.push("Apples");
function getShoppingListMsg() {
return `Current Shopping List: ${shoppingList}`;
function getShoppingListMsg(arr) {
return `Current Shopping List: ${arr}`;
}
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
shoppingList.push("Grapes");
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
console.log("It looks like we need to get some cooking oil.");
shoppingList.unshift("Vegetable Oil");
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
shoppingList.push("Popcorn", "Beef Jerky", "Potato Chips");
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
console.log("This looks like too much junk food.");
shoppingList.pop();
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
console.log("It might be nice to get a dessert.");
shoppingList.unshift("Chocolate Cake");
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
console.log("On second thought, maybe we should be more health conscious.");
@@ -80,37 +82,37 @@ console.log("It will be nice to have some fruit to eat.");
shoppingList.push("Apples");
function getShoppingListMsg() {
return `Current Shopping List: ${shoppingList}`;
function getShoppingListMsg(arr) {
return `Current Shopping List: ${arr}`;
}
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
shoppingList.push("Grapes");
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
console.log("It looks like we need to get some cooking oil.");
shoppingList.unshift("Vegetable Oil");
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
shoppingList.push("Popcorn", "Beef Jerky", "Potato Chips");
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
console.log("This looks like too much junk food.");
shoppingList.pop();
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
console.log("It might be nice to get a dessert.");
shoppingList.unshift("Chocolate Cake");
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
console.log("On second thought, maybe we should be more health conscious.");
shoppingList.shift();
shoppingList[0] = "Canola Oil";
console.log(getShoppingListMsg());
console.log(getShoppingListMsg(shoppingList));
```

View File

@@ -13,10 +13,10 @@ Add a `console.log` and call the `getShoppingListMsg` function inside of the `co
# --hints--
You should call the `getShoppingListMsg` function inside of the `console.log`.
You should call the `getShoppingListMsg(shoppingList)` function inside of the `console.log`.
```js
assert.match(code, /console\.log\(\s*getShoppingListMsg\(\)\s*\)/);
assert.match(code, /console\.log\(\s*getShoppingListMsg\(\s*shoppingList\s*\)\s*\)/);
```
# --seed--
@@ -32,8 +32,8 @@ console.log("It will be nice to have some fruit to eat.");
shoppingList.push("Apples");
function getShoppingListMsg() {
return `Current Shopping List: ${shoppingList}`;
function getShoppingListMsg(arr) {
return `Current Shopping List: ${arr}`;
}
--fcc-editable-region--