I’m working on a website currently, and something strange is going on.
I have this code:
![My code
CnP version:
“`javascript
var gameID = location.href.split(“&gameID=”)[1]
var quizID
firebase.database().ref(‘liveGames/’ + gameID).get().then((snapshot) => {
quizID = snapshot.val().quizID
})
console.log(“Quiz ID: ” + quizID)
When I try to run that, the console logs `Quiz ID: undefined
But when I put it in a different spot as shown below,
![Different spot
The console says the quiz ID properly. (It says `Quiz ID: 7630579719
Also, if I put it in either spot, DevTools says the correct thing as well:
![Correct DT 1
![Correct DT 2
Why does this all happen, and how can I fix it to never say `undefined
Additional details:
– I **do– I’m using Firebase version 8.4.3 (I find the modular v9 too hard to comprehend)
If you need any additional details, please ask in replies. Thanks a bunch!
Bost