Skip to main content

JavaScript Template Literals — exercises and bug fixes

5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Template Literals lesson. Every one is checked automatically in the browser — write the code, run it, and the tests tell you what still fails.

Exercises(5)

  1. 1

    Insert a value

    easy10 min

    Use a template literal to greet the name.

  2. 2

    Insert an expression

    easy10 min

    Show the price with twenty percent added.

  3. 3

    Use a ternary inside

    easy10 min

    Choose the singular or plural wording.

  4. 4

    Build a multi-line string

    easy10 min

    Report how many lines a two-line template holds.

  5. 5

    Combine two values

    medium10 min

    Report a name and an age in one sentence.

Find the bug(5)

  1. 1

    Fix the quotes used instead of backticks

    easy8 min

    A placeholder only works inside backticks.

  2. 2

    Fix the missing dollar sign

    easy8 min

    A placeholder needs a dollar before the braces.

  3. 3

    Fix the expression left outside

    easy8 min

    The calculation should happen inside the placeholder.

  4. 4

    Fix the joined string left as is

    easy8 min

    Rewrite the plus signs as a template literal.

  5. 5

    Fix the escaped newline in backticks

    easy8 min

    A real line break works directly inside backticks.

Ready to write the code?

The editor, the automatic checks and the worked solutions open up with an account.

Open the workspace