Skip to content
Advertisement

Make sure the string from the instruction is exactly what you are returning

Write a function called “show_excitement” where the string

“I am super excited for this course!” is returned exactly

5 times, where each sentence is separated by a single space.

Return the string with “return”.

You can only have the string once in your code.

Don’t just copy/paste it 5 times into a single variable!

JavaScript

How to solve this please help

Advertisement

Answer

Try the following:

JavaScript

You were almost there.

  1. You printed the sentence five times inside your function, but the instruction requires that you return a string (without printing inside the function). So use return followed by a string.

  2. The correct syntax for print is print(...), not print ....

  3. Putting a space between sentences is not quite clean with a for loop, because you need to take care of a trailing space (or leading space).

    For example,

    "I am super excited for this course! " * 5

    would result in

    "I am super excited for this course! ... I am super excited for this course! "

    (Note the final blank in the string.)

    Here I used join to insert spaces between five sentences. If the instructor wants you to learn for loop specifically, then you can try:

    JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement