The variable HardProblems is not being updated after the function completes. It is being updated within the loop but does not save. This is a firebase call. e.g. HardProblems.length is 0 but should be nonzero.
function getHardProblems(){
var HardProblems = [];
var foo = [];
db.collection("hardproblems")
.get()
.then(function(querySnapshot) {
querySnapshot.forEach(function(doc) {
// doc.data() is never undefined for query doc snapshots
//console.log(doc.id, " => ", doc.data());
HardProblems.push({docID: doc.id, ...doc.data()});
});
})
.catch(function(error) {
console.log("Error getting documents: ", error);
});
console.log("Got Hard Problems "+HardProblems.length)
}
HardProblemsasynchronously in success callback ofthen()that's why you are not getting anything in console. Try adding the log in callback method just after forEach