Skip to content

#300 Template String

Adam Kubiś edited this page Oct 28, 2026 · 1 revision

300 Template String

Write a template string according to the following example:

Example

const a = "John";

const b = "Joe";

const c = "Jack";

const template = "your template string" ➞ "Their names were: John, Joe and Jack."

modify the template variable to be a template string

Current source and tests | Catalog | Testing and tooling

Run this solution

From the cloned repository root, after installing dependencies:

node "Edabit/300 Template String.js"

Assertions are kept alongside the implementation and throw on failure. A successful run exits with code 0. Run every exercise with npm test or both lint and tests with npm run check.

Current implementation and tests

This is the complete executable file, including its imports and inline test cases. Run it from the repository, not as an isolated file copied out of the wiki. Line endings and trailing whitespace are normalized; executable tokens are unchanged.

//Write a template string according to the following example:
//Example
//const a = "John";
//const b = "Joe";
//const c = "Jack";
//const template = "your template string" ➞ "Their names were:  John,  Joe  and  Jack."
// modify the template variable to be a template string
function format(a, b, c) {
	// the result string must give: "Their names were: a, b and c."
	//const template = "your template string"
	const template = `Their names were: ${a}, ${b} and ${c}.`
	return template
}
import { assertEquals } from '../testHelper.js';
// test cases
assertEquals(format("John", "Joe", "Jack"), "Their names were: John, Joe and Jack.")
assertEquals(format("Peter", "Pin", "Pan"), "Their names were: Peter, Pin and Pan.")
assertEquals(format("E", "Da", "Bit"), "Their names were: E, Da and Bit.")
assertEquals(format("Bulbasaur", "Charmander", "Squirtle"), "Their names were: Bulbasaur, Charmander and Squirtle.")

Clone this wiki locally