I cant seem to post to ask for help on my code

An error occurred: Sorry you cannot post a link to that host.

to post external links you need to use the forum a bit, then you unlock that permission

thank you, actually i wanted to ask for help on my cash register machine as i cant seem to pass the last 2 tests due to decimal point problems. my array doesnt seem to subtracting both nickels on the last 2 test and im stuck on that 2 tests
. :sweat_smile:

you need to post your code for that.

Please update the message to include your code.

When you enter a code, 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 (').

this is my code so far for the cash register machine, its still returns 0.01penny when it should return INSUFFICIENT_FUNDS and the last one return 0.5000002 when it should have return 0.5

//Import from html
const cashInput = document.getElementById("cash");
const changeDue = document.getElementById("change-due");
const purchaseBtn = document.getElementById("purchase-btn");
const priceTotal = document.getElementById("price");

//declare variables
let price = 19.5;
let cid = [["PENNY", 0.01], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 1], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]];

const cashRegisterChecker = () => {

  let cash = parseFloat(cashInput.value);
  let change = cash - price;
  let totalCID = cid.reduce((prev,[_, next]) => prev + next, 0);

  //first condition checker
  if(cash < price){
    alert("Customer does not have enough money to purchase the item");
    changeDue.textContent = "";
  } else if (cash === price) {
    changeDue.textContent = "No change due - customer paid with exact cash";
  } else if (change > totalCID){
    changeDue.textContent = "Status: INSUFFICIENT_FUNDS";

  let currency = [
    {name:"ONE HUNDRED", value:100.0},
    {name:"TWENTY", value:20.0},
    {name:"TEN", value:10.0},
    {name:"FIVE", value:5.0},
    {name:"ONE", value:1.0},
    {name:"QUARTER", value:0.25},
    {name:"DIME", value:0.1},
    {name:"NICKEL", value:0.05},
    {name:"PENNY", value:0.01}

  cid = cid.reverse(); // reverse cid to match currency
  let changeArr = []; //create empty array to push in result

  //Iteration to find name + value
  for(let i = 0; i < cid.length; i++){
    //declare empty result for pushback
    let result = 0;
    while(currency[i].value <= change && cid[i][1] > 0){
      cid[i][1] -= currency[i].value;
      change = change.toFixed(2);
      change -= currency[i].value;
      result += currency[i].value;
    } //push result back to empty array
    if (result > 0){
      changeArr.push(`${cid[i][0]}: $${result}`);

  //2nd condition checker
  if (change < totalCID){
    changeDue.textContent = `"Status: OPEN ${changeArr}"`
  } else if(change === totalCID){
    changeDue.textContent = `"Status: CLOSED ${changeArr}"`


purchaseBtn.addEventListener("click", cashRegisterChecker);

You are running into the universal problem of storing floating point numbers (i.e. numbers with a decimal) in computers. Because there are an infinite amount of floating point numbers, computers have to use approximations to store them and thus sometimes what we would think of as simple calculations will give weird answers. For example, open up the console and type the following:

1.01 + 2.02 

We all know that the answer is 3.03, but JS has a very small, but different opinion.

Since these differences are so small, you could probably get away with just rounding the answers to two decimal places. But the better solution is to not use decimals in the first place. Instead of using dollar values, such as a penny being 0.01 dollars, can you think of an alternative monetary unit to use which wouldn’t require the use of decimals?

i see, thanks for the tip :smiley: