Space Separated Puzzle Explainer


Aim of the puzzle:
Use the .join method .join() to combine the items of an array into a string.

Walk through of solution:
The .join() method joins the items in an array into a string. To use it, attach .join() to the array you want to join. Inside the parentheses(), add a seperator, or a string to insert between each item as it gets joined to the next. If there is no argument inside the parenthesis, a comma is automatically used as a separator and inserted between items. If you don’t want a separator, use an empty string '' as an argument.

In the code that you start off with, there is an array, array, a variable declaration, joinedArray, and a console log that prints joinedArray. As it is, the joinedArray is incorrect. In this puzzle, you’ll fix it by changing the argument inside .join() so that it inserts a space between each item in the array as it gets joined to the next and becomes a string.

To complete the puzzle, inside the parentheses of .join(), change the argument to a single space ' '. Now, when the code runs, a space is inserted between the items in the sentence array as they combine to become a string.

Sample code solution:

let array = ['Make', 'this', 'a', 'sentence.']

let joinedArray = array.join(' ')


Javascript Concepts: Array, Array Methods, .join(), console.log(), Variable, Let

listed #2