Build a Cash Register Project - Build a Cash Register

Tell us what’s happening:

my code is working on my end with all the scenarios given but when i run the tests, from test 6 to the end.

here is part of the warning:

// running tests
When price is 20 and the value in the #cash element is 10, an alert should appear with the text "Customer does not have enough money to purchase the item".
When the value in the #cash element is less than price, an alert should appear with the text "Customer does not have enough money to purchase the item".

somehow it fails to read price and cash.

Your code so far

let price = 1.87;
let cid1 = [// 6 19.5 20 7 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]
];

 

const cashInput = document.getElementById('cash');
const total = document.getElementById('total-price');
const purchaseBtn = document.getElementById('purchase-btn');
const changeDue = document.getElementById('change-due');
const change = document.getElementById('change');
const cashDisplay = document.getElementById('cash-drawer-display');
const changeLbl = document.querySelector('.change-lbl');


let newCID = [];
let cash;
const drawerSum = (arr) => parseFloat(arr.reduce((sum, money) => sum + money[1], 0).toFixed(2));
let coinChange = 0;

  changeLbl.style.display = 'block'; // Make it visible

  if (dSum < coinChange){
    changeDue.innerHTML = `<p style="color: red">Status: INSUFFICIENT_FUNDS</p>`;
    change.style.color = 'red';
    change.textContent = `$${(cash - price).toFixed(2)}`;
  } else if (Math.abs(coinChange) < 0.01) { // Tolerance for floating-point precision; 
    changeDue.innerHTML = `<p>No change due - customer paid with exact cash</p>`;
    change.style.color = 'black';
    change.textContent = `$${(cash - price).toFixed(2)}`;
  }  else {
    change.style.color = 'black';
    change.textContent = `$${(cash - price).toFixed(2)}`;
    sortChange(coinChange);
  }
}





/* file: script.js */

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36

Challenge Information:

Build a Cash Register Project - Build a Cash Register

These global variables are not good for the re-usability of your function

let price = 1.87;
let cid = [// 6 19.5 20 7 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]
];

const cash = document.getElementById('cash');
const total = document.getElementById('total-price');
const purchaseBtn = document.getElementById('purchase-btn');
const changeDue = document.getElementById('change-due');
const change = document.getElementById('change');
const cashDisplay = document.getElementById('cash-drawer-display');
const changeLbl = document.querySelector('.change-lbl');








Yes. That is revised code.