2 years ago

#73673

test-img

4uckd3v

Javascript/Firebase - Why does function return undefined instead of true or false?

I'm use this function to check Answer. Value of compareAns should return true/false but it return undefined.

Return undefined

Data in firebase

function compareAns(quiz, ansIndex) {
    let ansRef = firebase
        .database()
        .ref("Questions/" + quiz + "/ans/" + ansIndex);
    ansRef.on("value", (snapshot) => {
        if (snapshot.exists()) {
            return snapshot.val().is_correct;
        } else console.log("No data");
    });
}

javascript

firebase

function

firebase-realtime-database

return-value

0 Answers

Your Answer

Accepted video resources