How to use template literals of ES6 script
I have been trying to solve a template literal question on hackerrank. It works fine on my local IDE but giving error on Hackerrank IDE. Heres the code two add two number and to print the result using template literal.
const sum = () => {
let a=1;
let b=2;
console.log(`The sum of ${a} and ${b} is ${a + b}`);
}
module.exports = {sum}
But it is producing the following error.
npm WARN [email protected] No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
audited 522 packages in 6.264s
found 611 vulnerabilities (378 low, 233 high)
run `npm audit fix` to fix them, or `npm audit` for details
> [email protected] test /projects/challenge
> mocha test --reporter mocha-junit-reporter
The sum of 1 and 2 is 3
npm ERR! Test failed. See above for more details.
I would like to add my view.
const sum = (a,b) => {
return `The sum of ${a} and ${b} is ${a + b}`;
};
module.exports = {sum}
Semicolons are important in these type of code