0

I am working on a small project that requires me to push numbers/operators into an array. When doing so the JavaScript console is telling me it is not possible to push to an undefined array. I am unsure as to what this means. Here is a small snippet of my code.

run: function(clicked){
        var numbers = [];
        var operations = [];

        switch(clicked){
            case "0":
            case "1":
            case "2":
            case "3":
            case "4":
            case "5":
            case "6":
            case "7":
            case "8":
            case "9":
                document.getElementById("dis1").innerHTML += clicked;
                break;
            case "point":
                document.getElementById("dis1").innerHTML += ".";
                break;
            case "mul":
                this.numbers.push(document.getElementById("dis1").innerHTML);
                document.getElementById("dis1").innerHTML = "";
                document.getElementById("dis1").innerHTML += "*";
                console.log(numbers);
                break;

As mentioned this is only a small snippet hence the unclosed functions etc.

1 Answer 1

2

You are misusing this

You should use numbers.push not this.numbers.push

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.