What is the most conventional way to add spacing between the literal string variables?

Tell us what’s happening:
Describe your issue in detail here.

So, the question asks to create a new sentence using following four variables - myNoun, my Adjective, myVerb and myAdverb. Since I cannot modify the defined literal string values, what is the most ideal way to add spacing between words in this situation?

I know my code passes the test but I want to know the convention that is popular amongst programmers!

Your code so far


const myNoun = "dog";
const myAdjective = "big";
const myVerb = "ran";
const myAdverb = "quickly";

// Only change code below this line
const wordBlanks = "My " + myAdjective + " " + myNoun + " " + myVerb + " " + myAdverb + "."; // Change this line
// Only change code above this line

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:96.0) Gecko/20100101 Firefox/96.0

Challenge: Word Blanks

Link to the challenge:

I don’t think there is a “simple” way.

If you have a bunch of strings and you want spaces between then, you could do something like:

['one', 'two', 'three'].join(' ')
// one two three

That could be put into a function, if you wanted.

I added [spoiler][/spoiler] tags since that is a working solution to a challenge.

The way you did it is how you normally would do string concatenation.

But you are likely to see template literals used in more modern code. At least for more complicated strings.

const wordBlanks = `My ${myAdjective} ${myNoun} ${myVerb} ${myAdverb}.`;
1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.