# The test for one of the challenges is not working

the test for ‘Cash Register’ challenge in ’ JavaScript Algorithms and Data Structures Projects’ keeps telling me that i have failed and I’am really sure that the output is exactly the same of whats expected
you can see it in the image bellow

its my last project on my certification by the way

Please post the actual code and not images.

When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (`</>`) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

thanks for the quick response
this is the test https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/cash-register
here is my code

``````// i am so sorry for this mess lol
const currency = {
'ONE HUNDERED': 100,
'TWENTY': 20,
'TEN': 10,
'FIVE': 5,
'ONE': 1,
'QUARTER': 0.25,
'DIME': 0.1,
'NICKEL': 0.05,
'PENNY': 0.01,
}

function sum(input){
let sum = 0
for ( let i in input){
sum += input[i]
}
return Math.round( sum * 1000 ) / 1000
}

function checkCashRegister(price, cash, cid) {

let output = {};

let dueChange = cash - price;
let change = {}

let store = {}
for (let i in cid){
store[cid[i][0]] = cid[i][1]
}

for ( let i in currency){
change[i] = 0
while( dueChange >= currency[i] & Math.round((store[i]-currency[i])*1000)/1000 >= 0){
dueChange = Math.round((dueChange - currency[i])*1000)/1000
change[i] += currency[i]
store[i] -= currency[i]
}
}

let changeArr = []

for ( let i in change){
changeArr.push([ [i][0], Math.round(change[i]*1000)/1000])
}

if ( dueChange > 0 ){
output.status = 'INSUFFICIENT_FUNDS'
changeArr = []
} else if(sum(store) == 0){
output.status = 'CLOSED'
let tempArr = []
for ( let i = changeArr.length - 1 ; i >= 0 ; i--){
tempArr.push(changeArr[i])
}
changeArr = tempArr
} else{
output.status = 'OPEN'
let tempArr = []
for ( let i in changeArr){
if ( changeArr[i][1] != 0){
tempArr.push(changeArr[i])
}
}
changeArr = tempArr
}
output.change = changeArr
return output;
}

console.log(checkCashRegister(19.5, 20, [["PENNY", 0.5], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 0], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]]));
``````

Check your spelling. Hint: in the `currency` object

1 Like

bruh
thanks that fixed it

Congrats on passing the challenge and getting the certificate.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.