mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-03-27 02:01:02 -04:00
fix: explain method chaining for step 18 of music player (#53693)
This commit is contained in:
@@ -7,9 +7,9 @@ dashedName: step-18
|
||||
|
||||
# --description--
|
||||
|
||||
Use the `join()` method to combine the `songsHTML` markup into a single string.
|
||||
Right now the `songsHTML` is an array. If you tried to display this as is, you would see the songs separated by commas. This is not the desired outcome because you want to display the songs as a list. To fix this, you will need to join the array into a single string by using the <dfn>join()</dfn> method.
|
||||
|
||||
The `join()` method is used to concatenate all the elements of an array into a single string. It takes an optional parameter called `separator` which is used to separate each element of the array. For example:
|
||||
The `join()` method is used to concatenate all the elements of an array into a single string. It takes an optional parameter called a `separator` which is used to separate each element of the array. For example:
|
||||
|
||||
```js
|
||||
const exampleArr = ["This", "is", "a", "sentence"];
|
||||
@@ -19,6 +19,12 @@ console.log(sentence); // Output: "This is a sentence"
|
||||
|
||||
Chain the `join()` method to your `map()` method and pass in an empty string for the separator.
|
||||
|
||||
To chain multiple methods together, you can call the `join()` method on the result of the `map()` method. For example:
|
||||
|
||||
```js
|
||||
array.map().join();
|
||||
```
|
||||
|
||||
# --hints--
|
||||
|
||||
You should add `join("")` to the existing code.
|
||||
|
||||
Reference in New Issue
Block a user