fix(curriculum): Shopping Cart optional braces (#56691)

This commit is contained in:
Supravisor
2024-10-29 13:28:37 +13:00
committed by GitHub
parent b6c47bf531
commit 6e618008e0
@@ -14,25 +14,25 @@ Add your callback function to the `forEach` method. It should take a `btn` param
You should use arrow syntax to add a callback function to the `forEach` method which takes a `btn` parameter.
```js
assert.match(code, /\[\s*\.\.\.addToCartBtns\s*\]\s*\.\s*forEach\s*\(\s*(\(\s*btn\s*\)|btn)\s*=>\s*\{/);
assert.match(code, /\[\s*\.\.\.addToCartBtns\s*\]\s*\.\s*forEach\s*\(\s*(\(\s*btn\s*\)|btn)\s*=>\s*(?:\{|\s*)/);
```
You should add an event listener to the `btn` variable.
```js
assert.match(code, /\[\s*\.\.\.addToCartBtns\s*\]\s*\.\s*forEach\s*\(\s*(\(\s*btn\s*\)|btn)\s*=>\s*\{\s*btn\s*\.\s*addEventListener\s*\(/);
assert.match(code, /\[\s*\.\.\.addToCartBtns\s*\]\s*\.\s*forEach\s*\(\s*(\(\s*btn\s*\)|btn)\s*=>\s*(?:\{\s*btn\s*\.\s*addEventListener\s*\(|\s*btn\s*\.\s*addEventListener\s*\()/);
```
You should listen for a `click` event on the `btn` variable.
```js
assert.match(code, /\[\s*\.\.\.addToCartBtns\s*\]\s*\.\s*forEach\s*\(\s*(?:\(\s*btn\s*\)|btn)\s*=>\s*\{\s*btn\s*\.\s*addEventListener\s*\(\s*('|"|`)click\1\s*,\s*/);
assert.match(code, /\[\s*\.\.\.addToCartBtns\s*\]\s*\.\s*forEach\s*\(\s*(?:\(\s*btn\s*\)|btn)\s*=>\s*(?:\{\s*btn\s*\.\s*addEventListener\s*\(\s*('|"|`)click\1\s*,\s*|\s*btn\s*\.\s*addEventListener\s*\(\s*('|"|`)click\2\s*,\s*)/);
```
You should add an empty callback function to the event listener. Remember to give it an `event` parameter.
```js
assert.match(code, /\[\s*\.\.\.addToCartBtns\s*\]\s*\.\s*forEach\s*\(\s*(?:\(\s*btn\s*\)|btn)\s*=>\s*\{\s*btn\s*\.\s*addEventListener\s*\(\s*('|"|`)click\1\s*,\s*(\(\s*event\s*\)|event)\s*=>\s*\{\s*\}\s*\)\s*;?\s*\}\s*\)/);
assert.match(code, /\[\s*\.\.\.addToCartBtns\s*\]\s*\.\s*forEach\s*\(\s*(?:\(\s*btn\s*\)|btn)\s*=>\s*(?:\{\s*btn\s*\.\s*addEventListener\s*\(\s*('|"|`)click\1\s*,\s*(\(\s*event\s*\)|event)\s*=>\s*\{\s*\}\s*\)\s*;?\s*\}\s*\)|\s*btn\s*\.\s*addEventListener\s*\(\s*('|"|`)click\3\s*,\s*(\(\s*event\s*\)|event)\s*=>\s*\{\s*\}\s*\)\s*;?\s*\))/);
```
# --seed--