0

I have made a function that should build the number for me, which was working and for some reason has stopped.

function buildNumber(num){
    console.log(num);
    if (calcState === true && currentNumber.toString().length < 9){
        if(currentNumber === 0){
            if (num === "."){
                currentNumber = Number(`${currentNumber}${num}`);
                console.log(currentNumber);
                checkDecimal = true;
                updateDisplay();
            } else if (num >=0 && num <= 9) {
                currentNumber = num;
                console.log(currentNumber);
                updateDisplay();
            }

        } else {
            if (num === "."){
                currentNumber = Number(`${currentNumber}${num}`);
                checkDecimal = true;
                console.log(currentNumber);
                updateDisplay();
            } else if (num >=0 && num <= 9) {
                currentNumber = Number(`${currentNumber}${num}`);
                console.log(currentNumber);
                updateDisplay();
            }
        }
    }
}

The event listener is triggered like so:

pointBtn.addEventListener("click", function(){
    console.log("Decimal pressed")
    if (checkDecimal === false){
        buildNumber(".");
    }
});

I'm just at a loss as to why it isn't triggering, the console.log just inside buildNumber() shows that the value is there when I click the button, it just doesn't do what I originally had it doing. Is there something glaringly obvious that I've missed?

  • Can you create a [mre]? –  Oct 08 '20 at 14:49
  • You didn't post the `updateDisplay()` code. – Pointy Oct 08 '20 at 14:50
  • @Pointy The update display code just dumps the current number into a display element. it has nothing to do with the computational side of things. – Spacejocks Oct 08 '20 at 16:56
  • @ChrisG I wouldn't know where to start at this moment in time, but the code is available at the link below, and the variables all link to the HTML output from an Adobe Animate Project. https://hastebin.com/osixafehur.js – Spacejocks Oct 08 '20 at 17:01

0 Answers0