Please help, Im stuck at the last project

I have no idea why is not working,
when I run it, [[quarter: 0.5]] keeps popping up from nowhere
when I try my code on console, it works well
is this an internal issue of freecodecamp?

heres my code


function checkCashRegister(price, cash, cid) {
  let change = (cash - price);
 
  let cidAmount = (cid[0][1])+(cid[1][1])+(cid[2][1])+(cid[3][1])+(cid[4][1])+(cid[5][1])+(cid[6][1])+(cid[7][1])+(cid[8][1]);
    
  if(cidAmount > change && cidAmount > 1.01){
     let tweenty=0;
     let maxTweenty=cid[7][1]
    //  console.log(maxTweenty)
     let ten=0;
     let maxTen=cid[6][1]
    //  console.log(maxTen)
     let five=0;
     let maxFive=cid[5][1]
    //  console.log(maxFive)
     let one=0;
     let maxOne=cid[4][1]
    //  console.log(maxOne)
     let quarter=0;
     let maxQuarter=cid[3][1]
    //  console.log(maxQuarter)
     let dime=0;
     let maxDime=cid[2][1]
    //  console.log(maxDime)
     let nickel=0;
     let maxNickel=cid[1][1]
      // console.log(maxNickel)
     let penny=0;
     let maxPenny=cid[0][1]
      // console.log(maxPenny)
//for - 1initial -2condition -3execute 4subtract
   for(change; change>=20 && maxTweenty != tweenty*20 && change>=20; change -=20){
      tweenty= tweenty+1;
      // console.log(change)
   }
     for(change; change>=10 && maxTen != ten*10 && change>=10; change -=10){
  ten =ten+1;
//  console.log(change) 
    }
    
    for(change; change>=5 && maxFive != five*5 && change>=5; change= change-5){
    
five = five+1;
// console.log(change)
      
    }
    for(change; change>=1 && maxOne != one*1 && change>=1; change= change-1){
      
one =one+1;
// console.log(change)
    
    }
    for(change; change>=0.25 && maxQuarter != quarter*0.25 && change>=0.25; change= change-0.25){
quarter=quarter+1;
// console.log(change)
    
    }
    for(change; change>=0.1 && maxDime != dime*0.1 && change>=0.1; change= change-0.1){
dime=dime+1;
// console.log(change)
    }
    for(change; change>=0.05 && maxNickel != nickel*0.05 && change>=0.05; change= change-0.05){
nickle=nickel+1;
// console.log(change)
    }
  
  // console.log(change)
    for(change; change>=0.009 && maxPenny != penny*0.01 && change>=0.009; change= change-0.01){
penny=penny+1;

    }
  
  //   console.log(tweenty)
  //   console.log(ten)
  //   console.log(five)
  //   console.log(one)
  //   console.log(quarter)
  //   console.log(dime)
  //   console.log(nickel)
  //   console.log(penny)
  // if(i=1){
        
  //     }

      let resultArr=[];
    
  
      if(tweenty !=0){
    resultArr.push(...[["TWEENTY", tweenty*20]])
      }
      if(ten !=0){
    resultArr.push(...[["TEN", ten*10]])
      }
        if(five !=0){
    resultArr.push(...[["FIVE", five*5]])
      }
        if(one !=0){
    resultArr.push(...[["ONE", one*1]])
      }
        if(quarter !=0){
    resultArr.push(...[["QUARTER", quarter*0.25]])
      }
        if(dime !=0){
    resultArr.push(...[["DIME", dime*0.1]])
      }
       if(nickel !=0){
   resultArr.push(...[["NICKEL", nickel*0.05]])
      }
        if(penny !=0){
    resultArr.push(...[["PENNY", penny*0.01]])
      }

    console.log(resultArr)
    return {
      
    status: "OPEN",
    change: resultArr
    
  };
  
  }else if(cidAmount == change){
return {
    status:"CLOSED",
    change:[["PENNY", 0.5], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 0], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]],
  };
  }
  
  else if(cidAmount<change || (cidAmount>change)&&(((parseInt(cidAmount)*100)%(parseInt(change)*100))) != 0 ){
return {
    status:"INSUFFICIENT_FUNDS",
    change:[],
  };
  }

}

checkCashRegister(3.26, 100, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]]);

please post a link to the exercise

I’ve edited your code for readability. 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 (').

oh sorry

this is the link of the exercise

the code is failing this test case:

checkCashRegister(3.26, 100, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]])

When I place this at the end of the editor I noticed that you are returning everything correctly but instead of TWENTY you are using TWEENTY
Try fixing that and hopefully that will work.

wow thank you so much, you saved me
after writing all the codes, I spent more than 3 hours to fix everything but it was just a typo…

1 Like

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