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);
Tudo estava claro?
Obrigado pelo seu feedback!
Seção 3. Capítulo 10
Pergunte à IA
Pergunte à IA
Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo
Suggested prompts:
Can you explain why we need to add spaces before some words?
What happens if I forget to add a space in one of the concatenations?
Can you show how to do this using template literals instead?
Awesome!
Completion rate improved to 2.33
Challenge: Build Sentences with JavaScript
Deslize para mostrar o 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);
Tudo estava claro?
Obrigado pelo seu feedback!
Seção 3. Capítulo 10