This works:
hero = "batman";
sidekick = "robin";
villain = "the joker"
function f(strings, good, helper, bad) {
console.log(strings); //expected: " and must team up to defeat "
console.log(good); //expect: "batman"
console.log(helper);//expect: "robin"
console.log(bad);//expect: "the joker"
}
f`${hero} and ${sidekick} must team up to defeat ${villain}`;
However when I store the template literal in a variable and try to pass the variable to the function it does not work:
hero = "batman";
sidekick = "robin";
villain = "the joker"
sentence = `${hero} and ${sidekick} must team up to defeat ${villain}`;
function f(strings, good, helper, bad) {
console.log(strings); //expected: " and must team up to defeat "
console.log(good); //expect: "batman"
console.log(helper);//expect: "robin"
console.log(bad);//expect: "the joker"
}
fsentence;
Is there a work-around?