To solve this, You should know about the difference between concatenation
and addtion
in javascript.
If you add two strings, You get concatenation of both strings as answer
"$45" + "$70" = "$45$70"
If you add two integers, you get addition.
45 + 70 = 115
So, to solve your problem, You need to first extract numbers from your variables and then do addition on them.
To extract numbers you can use any method but I am using split
.
To convert string into integer you can use parseInt
let num1 = "$45";
let num2 = "$70";
function getValue(num) {
return parseInt(num.split('$')[1]);
}
let sum = getValue(num1) + getValue(num2);
console.log("$" + sum);