function formatAmount() {
return "$" + amount.toFixed( 2 );
}
var amount = 99.99;
var kk = 11.11;
amount = formatAmount();
kk = formatAmount();
You should change your formatAmount function so that it takes the value to format as a param rather than acting on a global variable.
function formatAmount(a) {
return "$" + a.toFixed(2);
}
var amount = 99.99;
var kk = 11.11;
var amountF = formatAmount(amount);
var kkF = formatAmount(kk);
console.log(amountF);
console.log(kkF);