vendredi 1 octobre 2021

Why is the third part of the if statement running when it is not true? [closed]

I am trying to save a certain value into firestore if a certain condition is true. If the value of diffInTimeFirstBlock is greater than or equal to 0 and less than or equal to 35, the user is present. If diffInTimeFirstBlock is less than 0 and greater than -60, the user is tardy. If it is less than -60, the user is absent. I have intentionally made diffInTimeFirstBlock equal to 10, so the only part of the if statements that should run is the part that is greater than or equal to 0 and less than or equal to 35, but what ends up happening is that it skips over that part of the if statements and runs the part that would only run if diffInTimeFirstBlock is less than -60. Why is this happening, and how do I fix this?

Here is my code:

if (data == r112b2) {
    const diffInTimeFirstBlock = 10;
    if (diffInTimeFirstBlock < 0 && diffInTimeFirstBlock > -60) {
      firebase
        .firestore()
        .collection("112-2")
        .doc(firebase.auth().currentUser.uid)
        .update({
          status: "tardy",
        });
        Alert.alert("TARDY", data, [{ text: "OK" }]);
    } else if (diffInTimeFirstBlock >= 0 && diffInTimeFirstBlock <= 35) {
      firebase
        .firestore()
        .collection("112-2")
        .doc(firebase.auth().currentUser.uid)
        .update({
          status: "present",
        });
        Alert.alert("PRESENT", data, [{ text: "OK" }]);
    } else if (diffInTimeFirstBlock < -60) {
      firebase
        .firestore()
        .collection("112-2")
        .doc(firebase.auth().currentUser.uid)
        .update({
          status: "absent",
        });
        Alert.alert("ABSENT", data, [{ text: "OK" }]);
    } else {
      Alert.alert("QR DATA NOT SAVED", [{ text: "OK" }]);
    }
  }

Something else I find strange is that even though it saves absent into firestore, the alert that goes with it never pops up.

Aucun commentaire:

Enregistrer un commentaire