 Challenge: Build Sentences with JavaScript
Challenge: Build Sentences with JavaScript
Task
Let's build a full sentence using string concatenation.
- Create the string "I am hungry!"using the+operator.
- Add words with spaces (except the first one) using the +=operator.
12345678let sentence = ""; sentence += "___"; // "I" sentence += "___"; // "I am" sentence += "___"; // "I am hungry" sentence += "___"; // "I am hungry!" console.log(sentence);
The output should be:
I am hungry!
Add words with spaces (e.g.,ย " am",ย " hungry").
12345678let sentence = ""; sentence += "I"; // "I" sentence += " am"; // "I am" sentence += " hungry"; // "I am hungry" sentence += "!"; // "I am hungry!" console.log(sentence);
Everything was clear?
Thanks for your feedback!
Sectionย 3. Chapterย 10
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Suggested prompts:
Can you explain how string concatenation works in JavaScript?
What happens if I forget to add spaces between the words?
Can you show another example using different words?
Awesome!
Completion rate improved to 2.33 Challenge: Build Sentences with JavaScript
Challenge: Build Sentences with JavaScript
Swipe to show menu
Task
Let's build a full sentence using string concatenation.
- Create the string "I am hungry!"using the+operator.
- Add words with spaces (except the first one) using the +=operator.
12345678let sentence = ""; sentence += "___"; // "I" sentence += "___"; // "I am" sentence += "___"; // "I am hungry" sentence += "___"; // "I am hungry!" console.log(sentence);
The output should be:
I am hungry!
Add words with spaces (e.g.,ย " am",ย " hungry").
12345678let sentence = ""; sentence += "I"; // "I" sentence += " am"; // "I am" sentence += " hungry"; // "I am hungry" sentence += "!"; // "I am hungry!" console.log(sentence);
Everything was clear?
Thanks for your feedback!
Sectionย 3. Chapterย 10