function highlight(strings, ...values) {
return strings.reduce((result, str, i) => {
const value = values[i - 1];
const formatted =
typeof value === "number"
? `[${value.toFixed(2)}]`
: `<${String(value).toUpperCase()}>`;
return result + formatted + str;
});
}
const item = "sword";
const qty = 3;
const price = 9.5;
const output = highlight`You bought ${qty} ${item}s for $${price} each.`;
console.log(output); Post #3328
2.88K
CHALLENGE
- ❤ 6
- 👍 1