0

I am having a problem executing submitMyAnswer within the getTestContent function. I thought that it had something to do with the clearIntervals but it's not. I tried adding the whole content of the 'submitMyAnswer' function into my main function but it gives me an error cannot read property 'dispatch' of undefined. What should I do? Should I try 'returning' the method?

//other method is called submitMyAnswer
getTestContent() {
    this.gotEm2 = true;
    this.gotEm = false;
    localStorage.getItem("savedId");
    axios
        .get("https://www.derptech.site/MyComposer/", {
            params: {
                id: 8,
                testToken: this.selectedTest,
            },
        })
        .then((res) => {
            for (var l = 0; l < res.data.length; l++) {
                this.quizTime = res.data[l].Duration;
                this.testContentData.push({
                    testId: res.data[l].TestId,
                    daimage: res.data[l].DaImage,
                    question: res.data[l].Question,
                });
            }

            var totalSeconds;

            if (this.quizTime != 0) {

                if (localStorage.getItem("totalSeconds")) {
                    totalSeconds = localStorage.getItem("totalSeconds");
                } else {
                    totalSeconds = this.quizTime;
                }

                var minutesLabel = document.getElementById("minutes");
                var secondsLabel = document.getElementById("seconds");
                var startThisTime = setInterval(setTime, 1000);
                //setInterval(setTime, 1000);

                function setTime() {
                    --totalSeconds;
                    secondsLabel.innerHTML = pad(totalSeconds % 60);
                    minutesLabel.innerHTML = pad(parseInt(totalSeconds / 60));
                    localStorage.setItem("totalSeconds", totalSeconds);


                    if (totalSeconds <= 0) {
                        clearInterval(startThisTime);
                        this.submitMyAnswer();
                    }
                }


                function pad(val) {
                    var valString = val + "";
                    if (valString.length < 2) {
                        return "0" + valString;
                    } else {
                        return valString;
                    }
                }

                window.addEventListener("beforeunload", function(e) {
                    e.preventDefault();
                    s;
                    e.returnValue = "";
                });
            }

        });
},

0 Answers0