Im trying to find the value of sendback, however when I console.log(findavailbase()) it is undefined. I know im missing something obvious but Ive been looking for a good ten minutes and I cant find the issue. here is the code:
function findavailbase() {
var sql1 = `select capacitylimit,currentload,baseid from bases `;
con.query(sql1, function (err, result) {
if (err) throw err;
for (let i = 0; i < result.length; i++) {
if (result[i].capacitylimit > result[i].currentload) {
const sendback = result[i].baseid
return sendback
}
}
});
}
console.log(findavailbase())
Any help would be appreciated.