0061【Edabit ★☆☆☆☆☆】Format I: Template String

language_fundamentals strings

Instructions
Examples
const a = "John";
const b = "Joe";
const c = "Jack";
const template = "your template string" // "Their names were:  John,  Joe  and  Jack."
Tips
Notes
  • N/A
Solutions

// 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
}

TestCases
let Test = (function(){
    return {
        assertEquals:function(actual,expected){
            if(actual !== expected){
                let errorMsg = `actual is ${actual},${expected} is expected`;
                throw new Error(errorMsg);
            }
        },
        assertSimilar:function(actual,expected){
            if(actual.length != expected.length){
                throw new Error(`length is not equals, ${actual},${expected}`);
            }
            for(let a of actual){
                if(!expected.includes(a)){
                    throw new Error(`missing ${a}`);
                }
            }
        }
    }
})();


Test.assertEquals(format("John", "Joe", "Jack"), "Their names were: John, Joe and Jack.")
Test.assertEquals(format("Peter", "Pin", "Pan"), "Their names were: Peter, Pin and Pan.")
Test.assertEquals(format("E", "Da", "Bit"), "Their names were: E, Da and Bit.")
Test.assertEquals(format("Bulbasaur", "Charmander", "Squirtle"), "Their names were: Bulbasaur, Charmander and Squirtle.")
11-11 17:38