Skip to content

Commit de6ce16

Browse files
authored
fix(curriculum): always passing tests in Forum leaderboard (freeCodeCamp#55556)
1 parent 258d687 commit de6ce16

File tree

3 files changed

+26
-13
lines changed

3 files changed

+26
-13
lines changed

curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-asynchronous-programming-by-building-an-fcc-forum-leaderboard/645f8615fa144d01c476b22c.md

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,50 +15,59 @@ Inside the `img` tag, add a `src` attribute with the value of `${userAvatarUrl}`
1515

1616
# --hints--
1717

18-
You should return an empty template literal.
18+
You should return a template literal.
1919

2020
```js
2121
const emptyTemplateLiteral = /return\s*`(.*)`/;
22-
assert(code.match(emptyTemplateLiteral));
22+
assert.match(getReturnCode(code), emptyTemplateLiteral);
2323
```
2424

2525
You should have an `img` element inside the template literal.
2626

2727
```js
2828
const imgTag = /return\s*`<img[^>]*\\?>`/g;
29-
assert(code.match(imgTag));
29+
assert.match(getReturnCode(code), imgTag);
3030
```
3131

3232
You should have a `src` attribute inside the `img` tag.
3333

3434
```js
3535
const imgTagWithSrc = /return\s*`<img[^>]*src\s*=\s*('|")[^'"]*\1[^>]*\\?>`/g;
36-
assert(code.match(imgTagWithSrc));
36+
assert.match(getReturnCode(code), imgTagWithSrc);
3737
```
3838

3939
You should set the value for the `src` attribute to the constant named `userAvatarUrl`.
4040

4141
```js
4242
const srcValue = /return\s*`<img[^>]*src\s*=\s*('|")\s*\${userAvatarUrl}\s*\1[^>]*\\?>`/g;
43-
assert(code.match(srcValue));
43+
assert.match(getReturnCode(code), srcValue);
4444
```
4545

4646
You should have an `alt` attribute after the `src` attribute.
4747

4848
```js
4949
const imageTagWithSrcAndAlt = /return\s*`<img[^>]*src\s*=\s*('|")[^'"]*\1[^>]*alt\s*=\s*('|")[^'"]*\2[^>]*\\?>`/g;
50-
assert(code.match(imageTagWithSrcAndAlt));
50+
assert.match(getReturnCode(code), imageTagWithSrcAndAlt);
5151
```
5252

5353
You should set the value of the `alt` attribute to the constant named `user.name`.
5454

5555
```js
5656
const altValue = /return\s*`<img[^>]*src\s*=\s*('|")\s*\${userAvatarUrl}\s*\1[^>]*alt\s*=\s*('|")\s*\${user\.name}\s*\2[^>]*\\?>`/g;
57-
assert(code.match(altValue));
57+
assert.match(getReturnCode(code), altValue);
5858
```
5959

6060
# --seed--
6161

62+
## --after-user-code--
63+
64+
```js
65+
function getReturnCode(code) {
66+
const returnAndRest = code.split(/:\s*avatar\s*;?/)?.[1];
67+
return returnAndRest?.split(/\}\s*\}\s*\)\s*;?\s*\}\s*;?/)?.[0];
68+
}
69+
```
70+
6271
## --seed-contents--
6372
6473
```html

curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-asynchronous-programming-by-building-an-fcc-forum-leaderboard/646474a88d0d4a016f895ba8.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,17 @@ Inside the second `td` element, add a `div` element with a class name of `avatar
1616
You should have a `div` element inside the second `td` element.
1717

1818
```js
19-
const joinTest = /<div\b[^>]*>([\s\S]*?)<\/div>/gm;
20-
assert(code.match(joinTest));
19+
const secondTd = code.split(/postsContainer\.innerHTML = topics\.map/)?.[1]?.split(/\s*<\/td>\s*<td>/)?.[1];
20+
const divTest = /<div\b[^>]*>([\s\S]*?)<\/div>/gm;
21+
assert.match(secondTd?.split(/<\/td>/)?.[0], divTest);
2122
```
2223
2324
Your opening `div` tag should have a class attribute with the value of `avatar-container`.
2425
2526
```js
26-
const divRegexTest = /<div\b[^>]*\bclass\s*=\s*"[^"]*\bavatar-container\b[^"]*"[^>]*>([\s\S]*?)<\/div>/gm;
27-
assert(code.match(divRegexTest));
27+
const secondTd = code.split(/postsContainer\.innerHTML = topics\.map/)?.[1]?.split(/\s*<\/td>\s*<td>/)?.[1];
28+
const divRegexTest = /<div\b[^>]*\bclass\s*=\s*('|")avatar-container\1[^>]*>([\s\S]*?)<\/div>/gm;
29+
assert.match(secondTd?.split(/<\/td>/)?.[0], divRegexTest);
2830
```
2931
3032
# --seed--

curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-asynchronous-programming-by-building-an-fcc-forum-leaderboard/64649b108df035051cb2ba2d.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ And with those changes, your freeCodeCamp forum leaderboard project is now compl
1616
Your opening anchor tag should have a `target` attribute set to `_blank`.
1717

1818
```js
19-
assert.match(code, /<a\s+(?:[^>]*\s+)?target\s*=\s*('|")_blank\1(?:\s+[^>]*)?>.*<\/a>/s);
19+
const firstTd = code.split(/postsContainer\.innerHTML = topics\.map/)?.[1]?.split(/\s*<tr>\s*<td>/)?.[1];
20+
assert.match(firstTd?.split(/<\/td>/)?.[0], /<a\s+(?:[^>]*\s+)?target\s*=\s*('|")_blank\1(?:\s+[^>]*)?>.*<\/a>/s);
2021
```
2122
2223
Your opening anchor tag should have an `href` attribute set to `${forumTopicUrl}${slug}/${id}`.
2324
2425
```js
25-
assert.match(code, /<a\s+(?:[^>]*\s+)?href\s*=\s*('|")\${forumTopicUrl}\${slug}\/\${id}\1(?:\s+[^>]*)?>.*<\/a>/s);
26+
const firstTd = code.split(/postsContainer\.innerHTML = topics\.map/)?.[1]?.split(/\s*<tr>\s*<td>/)[1];
27+
assert.match(firstTd?.split(/<\/td>/)?.[0], /<a\s+(?:[^>]*\s+)?href\s*=\s*('|")\${forumTopicUrl}\${slug}\/\${id}\1(?:\s+[^>]*)?>.*<\/a>/s);
2628
```
2729
2830
# --seed--

0 commit comments

Comments
 (0)