I'm having trouble getting access to the codeToCheck
outside of the functions. console.log(abc + ' holy')
is printing undefined holy
however the console.log(codeToCheck)
is printing a random code as it should
var abc = codeGenerator();
function codeGenerator() {
var randomCode = crypto.randomBytes(3).toString("hex");
codeChecker(randomCode)
return
}
function codeChecker(codeToCheck) {
mongoose.model("User").find({ refCode: codeToCheck }, function(err, user) {
if (err) {
console.log(err);
} else {
if (user.length > 0) {
codeGenerator()
} else {
console.log(codeToCheck)
return
}
}
});
}
console.log(abc + ' holy')