Skip to content

Implement new Concept Exercise: Template Strings and Ternary #1009

Closed
@junedev

Description

@junedev

Getting started

Here you can read about what Concept Exercises are and how they are structured:

If you have not done so yet, it is probably also helpful to do a couple of "Learning Exercises" (this is how they are called on the site) yourself. You can also look at the code of an existing concept exercise like bird-watcher (concept for-loops) for reference.

Goal

The goal of this exercise is to introduce template strings (also called template literals or string interpolation) and the ternary operator.

Concepts

The following concept pages need to be created. You can combine the introduction.md files from the concepts and use that as introduction.md for the concept exercise. No need to create different content at this point.

  • template-strings (should include that there is no classical string formatting library in JS and show some alternatives)
  • conditionals-ternary

The ternary operator is included here because it probably does not make sense to have a separate concept exercise for it and it might be useful in the context of template strings. Additionally the conditionals concept/exercise was already quite "full".

Learning Objectives

In the concepts the student should learn about the following topics and then practice them in the concept exercise.

  • How to write a simple template string (point out that backticks are different from single quotes)
  • How to use template strings to create multi-line strings
  • How to do interpolation in template strings (explain that non-string values are converted to strings and that expressions are evaluated)
  • That JS does not have a classical built-in string formatting library where you can do things like printf("%9.2f", num)
  • Replacements for string formatting, e.g. how to use toFixed to format numbers
  • How to use the conditional operator/ternary operator

Out of Scope

  • Nested and tagged template strings
  • Conditional Chains (could also be part of "about" but since they are not very readable I would rather not mention them explicitly, people can still read about it on the general MDN page)

About.md of the Concept

Here some ideas of what could be mentioned.

  • Pitfall: rounding applied by toFixed is not mathematically correct in all cases
  • ...

Prerequisites

  • strings
  • conditionals
  • type-conversion

At this point, the student already knows about truthy and falsy. See this list for details on the learning curve we are aiming for.

Exercise Idea

Swift Custom Signs Exercise could serve as inspiration for the story but it needs to be changed a bit.

  • Omit the part with characters.
  • Adapt the last task to include some calculation in the template string.
  • Add a task that utilizes the ternary operator.

Help

You can choose to do this solo-style, or collaborate with multiple people on this. The suggested approach is to

  1. First accept this issue by saying "I'd like to work on this" (no need to wait for a response, just go with it) and optionally request that someone works with you (and wait for a second person to accept your request).
  2. Use this issue to discuss any questions you have, what should be included in the content and what not and to collect reference material.
  3. Create a PR and set "exercism/javascript" as reviewers. Additionally you can write in #maintaining-javascript that your PR is ready for review. Once you incorporated any critical feedback that the reviewer might give you and the PR is approved, it will be merged by a maintainer.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions