Skip to content

Commit 2be04b8

Browse files
monbehreMonica Behrendraisedadeadriyueguang
authored
fix(curriculum): allow all valid versions of browser alert (freeCodeCamp#59721)
Co-authored-by: Monica Behrend <[email protected] config --global user.name> Co-authored-by: Mrugesh Mohapatra <[email protected]> Co-authored-by: riyueguang <[email protected]>
1 parent df7c9bc commit 2be04b8

File tree

8 files changed

+18
-18
lines changed

8 files changed

+18
-18
lines changed

curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-basic-oop-by-building-a-shopping-cart/63f038e671d3f73d5a041973.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ assert.match(cart.clearCart.toString(), /if\s*\(\s*!\s*this\s*\.\s*items\s*\.\s*
2424
Your `if` statement should display an `alert` to the user with the text `Your shopping cart is already empty`.
2525

2626
```js
27-
assert.match(cart.clearCart.toString(), /if\s*\(\s*!\s*this\s*\.\s*items\s*\.\s*length\s*\)\s*\{\s*alert\s*\(\s*('|"|`)Your shopping cart is already empty\1\s*\)\s*/);
27+
assert.match(cart.clearCart.toString(), /if\s*\(\s*!\s*this\s*\.\s*items\s*\.\s*length\s*\)\s*\{\s*(?:window\.|globalThis\.)?alert\s*\(\s*('|"|`)Your shopping cart is already empty\1\s*\)\s*/);
2828
```
2929

3030
Your `if` statement should return from the function.
3131

3232
```js
33-
assert.match(cart.clearCart.toString(), /if\s*\(\s*!\s*this\s*\.\s*items\s*\.\s*length\s*\)\s*\{\s*alert\s*\(\s*('|"|`)Your shopping cart is already empty\1\s*\)\s*;?\s*return\s*;?\s*\}/);
33+
assert.match(cart.clearCart.toString(), /if\s*\(\s*!\s*this\s*\.\s*items\s*\.\s*length\s*\)\s*\{\s*(?:window\.|globalThis\.)?alert\s*\(\s*('|"|`)Your shopping cart is already empty\1\s*\)\s*;?\s*return\s*;?\s*\}/);
3434
```
3535

3636
# --seed--

curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63c9bc53735149084390e5d0.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,20 @@ Using a template literal, in your `if` block, call the `alert()` function to tel
1616
You should call the `alert()` function in your `if` block.
1717

1818
```js
19-
assert.match(getCaloriesFromInputs.toString(), /if\s*\(\s*invalidInputMatch\s*\)\s*\{\s*alert\(/);
19+
assert.match(getCaloriesFromInputs.toString(), /if\s*\(\s*invalidInputMatch\s*\)\s*\{\s*(?:window\.|globalThis\.)?alert\(/);
2020
```
2121

2222
You should use a template literal to pass the `"Invalid Input: "` message to the `alert()` function.
2323

2424
```js
2525
// because it transforms template literals...
26-
assert.match(code.split(/function\s+getCaloriesFromInputs/)[1], /alert\(\s*`Invalid Input: /);
26+
assert.match(code.split(/function\s+getCaloriesFromInputs/)[1], /(?:window\.|globalThis\.)?alert\(\s*`Invalid Input: /);
2727
```
2828

2929
You should display the first element of the `invalidInputMatch` array after the `"Invalid Input: "` text by using a template literal.
3030

3131
```js
32-
assert.match(code.split(/function\s+getCaloriesFromInputs/)[1], /alert\(\s*`Invalid Input: \${invalidInputMatch\s*\[\s*0\s*\]\s*}`\s*\)/);
32+
assert.match(code.split(/function\s+getCaloriesFromInputs/)[1], /(?:window\.|globalThis\.)?alert\(\s*`Invalid Input: \${invalidInputMatch\s*\[\s*0\s*\]\s*}`\s*\)/);
3333
```
3434

3535
# --seed--

curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63c9bcc26219e7090da0f549.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ Still within your `if` block, set `isError` to `true` and return `null`.
1616
After your `alert`, you should set `isError` to `true`.
1717

1818
```js
19-
assert.match(code.split(/function\s+getCaloriesFromInputs/)[1], /alert\(\s*`Invalid Input: \${invalidInputMatch\s*\[\s*0\s*\]\s*}`\s*\)\s*;?\s*isError\s*=\s*true/);
19+
assert.match(code.split(/function\s+getCaloriesFromInputs/)[1], /(?:window\.|globalThis\.)?alert\(\s*`Invalid Input: \${invalidInputMatch\s*\[\s*0\s*\]\s*}`\s*\)\s*;?\s*isError\s*=\s*true/);
2020
```
2121

2222
After you modify `isError`, you should `return` the value `null`.
2323

2424
```js
25-
assert.match(code.split(/function\s+getCaloriesFromInputs/)[1], /alert\(\s*`Invalid Input: \${invalidInputMatch\s*\[\s*0\s*\]\s*}`\s*\)\s*;?\s*isError\s*=\s*true\s*;?\s*return\s+null\s*;?\s*\}/);
25+
assert.match(code.split(/function\s+getCaloriesFromInputs/)[1], /(?:window\.|globalThis\.)?alert\(\s*`Invalid Input: \${invalidInputMatch\s*\[\s*0\s*\]\s*}`\s*\)\s*;?\s*isError\s*=\s*true\s*;?\s*return\s+null\s*;?\s*\}/);
2626
```
2727

2828
# --seed--

curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-recursion-by-building-a-decimal-to-binary-converter/64475c0b61cddb6feaab4e2e.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Note that `alert()` is a method on the `window` object in the browser, so you ca
1818
You should call the `alert()` method within the body of your `if` statement within `checkUserInput`.
1919

2020
```js
21-
assert.match(String(checkUserInput), /if\s*\(\s*.+\s*\)\s*\{\s*(window\s*.)?\s*alert\(/);
21+
assert.match(String(checkUserInput), /if\s*\(\s*.+\s*\)\s*\{\s*(?:window\.|globalThis\.)?alert\(/);
2222
```
2323

2424
When there is a falsy value in the `#number-input` element and the `checkUserInput()` function is called, the `alert()` method should display the text `"Please provide a decimal number greater than or equal to 0"`.

curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-recursion-by-building-a-decimal-to-binary-converter/644760f4fb15ce765baebb62.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Add the `return` keyword after `alert()`.
1616
You should use the `return` keyword after `alert()`.
1717

1818
```js
19-
assert.match(String(checkUserInput), /if\s*\(\s*.+\s*\)\s*\{\s*(window\s*.)?\s*alert\(\s*('|"|`)please provide a decimal number greater than or equal to 0\2\s*\)\s*;?\s*return\s*;?\s*\}/i);
19+
assert.match(String(checkUserInput), /if\s*\(\s*.+\s*\)\s*\{\s*(window\s*.|globalThis\s*.)?\s*alert\(\s*('|"|`)please provide a decimal number greater than or equal to 0\2\s*\)\s*;?\s*return\s*;?\s*\}/i);
2020
```
2121

2222
# --seed--

curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-recursion-by-building-a-decimal-to-binary-converter/6448b2c9aec64c0ecd41573d.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ assert.notMatch(String(checkUserInput), /alert\(\s*('|"|`)\s*(\s|.)*\s*\1\s*\)\s
2020
You should call the `decimalToBinary` function after the `if` statement within the body of your `checkUserInput` function.
2121

2222
```js
23-
assert.match(String(checkUserInput), /alert\(\s*('|"|`)\s*(\s|.)*\s*\1\s*\)\s*;?\s*return\s*;?\s*\}\s*decimalToBinary\(/);
23+
assert.match(String(checkUserInput), /(?:window\.|globalThis\.)?alert\(\s*('|"|`)\s*(\s|.)*\s*\1\s*\)\s*;?\s*return\s*;?\s*\}\s*decimalToBinary\(/);
2424
```
2525

2626
You should use `parseInt()` to convert the `value` of `numberInput` into a number, and pass that as an argument to the `decimalToBinary` function.

curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-regular-expressions-by-building-a-spam-filter/641cdebe67ec0f25a4798356.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ assert.match(code, /checkMessageButton\.addEventListener\(\s*('|"|`)click\1\s*,\
2828
Your `if` statement should display an alert to the user with the message `"Please enter a message."`.
2929

3030
```js
31-
assert.match(code, /checkMessageButton\.addEventListener\(\s*('|"|`)click\1\s*,\s*\(\s*\)\s*=>\s*\{\s*if\s*\(\s*(?:messageInput\.value\s*===?\s*('|"|`)\2|('|"|`)\3\s*===?\s*messageInput\.value)\s*\)\s*\{\s*alert\(\s*('|"|`)Please enter a message\.\4\s*\)/)
31+
assert.match(code, /checkMessageButton\.addEventListener\(\s*('|"|`)click\1\s*,\s*\(\s*\)\s*=>\s*\{\s*if\s*\(\s*(?:messageInput\.value\s*===?\s*('|"|`)\2|('|"|`)\3\s*===?\s*messageInput\.value)\s*\)\s*\{\s*(?:window\.|globalThis\.)?alert\(\s*('|"|`)Please enter a message\.\4\s*\)/)
3232
```
3333

3434
Your `if` statement should exit the function execution.
3535

3636
```js
37-
assert.match(code, /checkMessageButton\.addEventListener\(\s*('|"|`)click\1\s*,\s*\(\s*\)\s*=>\s*\{\s*if\s*\(\s*(?:messageInput\.value\s*===?\s*('|"|`)\2|('|"|`)\3\s*===?\s*messageInput\.value)\s*\)\s*\{\s*alert\(\s*('|"|`)Please enter a message\.\4\s*\)\s*;?\s*return\s*;?\s*\}\s*\}/)
37+
assert.match(code, /checkMessageButton\.addEventListener\(\s*(['"`])click\1\s*,\s*\(\s*\)\s*=>\s*\{\s*if\s*\(\s*(?:messageInput\.value\s*===?\s*(['"`])\2|(['"`])\3\s*===?\s*messageInput\.value)\s*\)\s*\{\s*(?:window\.|globalThis\.)?alert\(\s*(['"`])Please enter a message\.\4\s*\)\s*;?\s*return\s*;?\s*\}\s*\}/)
3838
```
3939

4040
# --seed--

curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-regular-expressions-by-building-a-spam-filter/641cdf57c3f7ee276e1d9b32.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,37 +24,37 @@ Then set the `messageInput` element's `value` property to an empty string.
2424
You should use the assignment operator to set the `textContent` property of the `result` element.
2525

2626
```js
27-
assert.match(code, /checkMessageButton\.addEventListener\(\s*('|"|`)click\1\s*,\s*\(\s*\)\s*=>\s*\{\s*if\s*\(\s*messageInput\.value\s*===\s*('|"|`)\2\s*\)\s*\{\s*alert\(\s*('|"|`)Please enter a message\.\3\s*\)\s*;?\s*return\s*;?\s*\}\s*result\.textContent\s*\=\s*/)
27+
assert.match(code, /checkMessageButton\.addEventListener\(\s*('|"|`)click\1\s*,\s*\(\s*\)\s*=>\s*\{\s*if\s*\(\s*messageInput\.value\s*===\s*('|"|`)\2\s*\)\s*\{\s*(?:window\.|globalThis\.)?alert\(\s*('|"|`)Please enter a message\.\3\s*\)\s*;?\s*return\s*;?\s*\}\s*result\.textContent\s*\=\s*/)
2828
```
2929

3030
You should call the `isSpam()` function after the assignment operator `=` and before the `?` ternary operator.
3131

3232
```js
33-
assert.match(code, /checkMessageButton\.addEventListener\(\s*('|"|`)click\1\s*,\s*\(\s*\)\s*=>\s*\{\s*if\s*\(\s*messageInput\.value\s*===\s*('|"|`)\2\s*\)\s*\{\s*alert\(\s*('|"|`)Please enter a message\.\3\s*\)\s*;?\s*return\s*;?\s*\}\s*result\.textContent\s*\=\s*isSpam\(.*\)\s*\?/)
33+
assert.match(code, /checkMessageButton\.addEventListener\(\s*('|"|`)click\1\s*,\s*\(\s*\)\s*=>\s*\{\s*if\s*\(\s*messageInput\.value\s*===\s*('|"|`)\2\s*\)\s*\{\s*(?:window\.|globalThis\.)?alert\(\s*('|"|`)Please enter a message\.\3\s*\)\s*;?\s*return\s*;?\s*\}\s*result\.textContent\s*\=\s*isSpam\(.*\)\s*\?/)
3434
```
3535

3636
You should use ternary syntax to check the truthiness of `isSpam(messageInput.value)`.
3737

3838
```js
39-
assert.match(code, /checkMessageButton\.addEventListener\(\s*('|"|`)click\1\s*,\s*\(\s*\)\s*=>\s*\{\s*if\s*\(\s*messageInput\.value\s*===\s*('|"|`)\2\s*\)\s*\{\s*alert\(\s*('|"|`)Please enter a message\.\3\s*\)\s*;?\s*return\s*;?\s*\}\s*result\.textContent\s*\=\s*isSpam\(\s*messageInput\.value\s*\)\s*\?/)
39+
assert.match(code, /checkMessageButton\.addEventListener\(\s*('|"|`)click\1\s*,\s*\(\s*\)\s*=>\s*\{\s*if\s*\(\s*messageInput\.value\s*===\s*('|"|`)\2\s*\)\s*\{\s*(?:window\.|globalThis\.)?alert\(\s*('|"|`)Please enter a message\.\3\s*\)\s*;?\s*return\s*;?\s*\}\s*result\.textContent\s*\=\s*isSpam\(\s*messageInput\.value\s*\)\s*\?/)
4040
```
4141

4242
The truthy expression of your ternary should set the `textContent` property of the `result` element to `"Oh no! This looks like a spam message."`.
4343

4444
```js
45-
assert.match(code, /checkMessageButton\.addEventListener\(\s*('|"|`)click\1\s*,\s*\(\s*\)\s*=>\s*\{\s*if\s*\(\s*messageInput\.value\s*===\s*('|"|`)\2\s*\)\s*\{\s*alert\(\s*('|"|`)Please enter a message\.\3\s*\)\s*;?\s*return\s*;?\s*\}\s*result\.textContent\s*\=\s*isSpam\(\s*messageInput\.value\s*\)\s*\?\s*('|"|`)Oh no! This looks like a spam message.\4\s*:/);
45+
assert.match(code, /checkMessageButton\.addEventListener\(\s*('|"|`)click\1\s*,\s*\(\s*\)\s*=>\s*\{\s*if\s*\(\s*messageInput\.value\s*===\s*('|"|`)\2\s*\)\s*\{\s*(?:window\.|globalThis\.)?alert\(\s*('|"|`)Please enter a message\.\3\s*\)\s*;?\s*return\s*;?\s*\}\s*result\.textContent\s*\=\s*isSpam\(\s*messageInput\.value\s*\)\s*\?\s*('|"|`)Oh no! This looks like a spam message.\4\s*:/);
4646
```
4747

4848
The falsy expression of your ternary should set the `textContent` property of the `result` element to `"This message does not seem to contain any spam."`.
4949

5050
```js
51-
assert.match(code, /checkMessageButton\.addEventListener\(\s*('|"|`)click\1\s*,\s*\(\s*\)\s*=>\s*\{\s*if\s*\(\s*messageInput\.value\s*===\s*('|"|`)\2\s*\)\s*\{\s*alert\(\s*('|"|`)Please enter a message\.\3\s*\)\s*;?\s*return\s*;?\s*\}\s*result\.textContent\s*\=\s*isSpam\(\s*messageInput\.value\s*\)\s*\?\s*('|"|`)Oh no! This looks like a spam message.\4\s*:\s*('|"|`)This message does not seem to contain any spam.\5\s*;?\s*/);
51+
assert.match(code, /checkMessageButton\.addEventListener\(\s*('|"|`)click\1\s*,\s*\(\s*\)\s*=>\s*\{\s*if\s*\(\s*messageInput\.value\s*===\s*('|"|`)\2\s*\)\s*\{\s*(?:window\.|globalThis\.)?alert\(\s*('|"|`)Please enter a message\.\3\s*\)\s*;?\s*return\s*;?\s*\}\s*result\.textContent\s*\=\s*isSpam\(\s*messageInput\.value\s*\)\s*\?\s*('|"|`)Oh no! This looks like a spam message.\4\s*:\s*('|"|`)This message does not seem to contain any spam.\5\s*;?\s*/);
5252
```
5353

5454
After your ternary, set the `value` property on the `messageInput` element to an empty string.
5555

5656
```js
57-
assert.match(code, /checkMessageButton\.addEventListener\(\s*('|"|`)click\1\s*,\s*\(\s*\)\s*=>\s*\{\s*if\s*\(\s*messageInput\.value\s*===\s*('|"|`)\2\s*\)\s*\{\s*alert\(\s*('|"|`)Please enter a message\.\3\s*\)\s*;?\s*return\s*;?\s*\}\s*result\.textContent\s*\=\s*isSpam\(\s*messageInput\.value\s*\)\s*\?\s*('|"|`)Oh no! This looks like a spam message.\4\s*:\s*('|"|`)This message does not seem to contain any spam.\5\s*;?\s*messageInput\.value\s*=\s*('|"|`)\6\s*;?\s*\}/)
57+
assert.match(code, /checkMessageButton\.addEventListener\(\s*('|"|`)click\1\s*,\s*\(\s*\)\s*=>\s*\{\s*if\s*\(\s*messageInput\.value\s*===\s*('|"|`)\2\s*\)\s*\{\s*(?:window\.|globalThis\.)?alert\(\s*('|"|`)Please enter a message\.\3\s*\)\s*;?\s*return\s*;?\s*\}\s*result\.textContent\s*\=\s*isSpam\(\s*messageInput\.value\s*\)\s*\?\s*('|"|`)Oh no! This looks like a spam message.\4\s*:\s*('|"|`)This message does not seem to contain any spam.\5\s*;?\s*messageInput\.value\s*=\s*('|"|`)\6\s*;?\s*\}/)
5858
```
5959

6060
# --seed--

0 commit comments

Comments
 (0)