Help: Need help with my code Exact Change JS

How can I make my result array contain numbers instead of string? My code does not pass any tests even though it results correct text in that cases where it should return a string. Please help.
My code here:

´´´
var name = []; //name of every currency
var valueArr = []; /value of what we have in
pennies
/
var totalChange= 0;
var arr = [10000,2000,1000,500,100,25,10,5,1]; /value of every currency in
pennies
/
function checkCashRegister(price, cash, cid) {
var change = 100*(cash-price); //change to pay, in pennies
cid.reverse(); //reverse cid to get Hundreds first
for (var i= 0; i< cid.length; i++){
valueArr.push(Math.round(100.00*(cid[i][1]))); //make valueArr Array
name.push(cid[i][0]); //make name Array
}
totalChange = valueArr.reduce(function (a, b) { //sum all change
return a + b;
});
if (totalChange < change ){ //check for enough change
return “Insufficient Funds”;
} else if (totalChange === change){ //for just enough
return “Closed”;
}

var result = arr.reduce(function(acc, next, index){ /loop trough arrays for
what currency needed
/
if (change>= next){
var currentValue= 0;
while(change >= next && valueArr[index]>= next){
currentValue+= next/100.00;
change-= next;
valueArr[index]-= next;
}
acc.push([name[index],currentValue.toFixed(2)]);/get two decimals to
currentValue
/
return acc;
}else{
return acc;
}
},[]);

return result;
}

checkCashRegister(19.50, 20.00, [[“PENNY”, 0.01], [“NICKEL”, 0], [“DIME”, 0], [“QUARTER”, 0], [“ONE”, 0], [“FIVE”, 0], [“TEN”, 0], [“TWENTY”, 0], [“ONE HUNDRED”, 0]]); ```

Would you mind putting 3 back ticks before and after your code, to make it more readable? Also, are you missing a couple lines at the top?

All cods are there, and now some backticks also.

You can just use Number(‘string’) this will transform your string into number

But I do not understand where in my code my (initial) numbers became strings. I used numbers initialy and I used toFixed to get 2 decimals…Where did I converte them to string? So many questions :slight_smile:

The toFixed converted them to string.

Is there another way to get decimals without converting to string?

I removed the "toFixed"and moved the vars that was at the beginning of the code to be inside the function function checkCashRegister(price, cash, cid) { and that solved the problems.
Thanks for your help rmdawson71 and AndreiCalazans

So HAPPY to have passed this challenge :slight_smile: