I am new to Javascript, and Trying to write a function inside a function, but it always show undefine.
function csnotebook(){  
    function calculate_mw(peptide){     
        var total_mw=0;                                 
        var split_peptide = peptide.split("-");
        // Check if the blog id is found in database
        Aa.findOne({ three_letter: split_peptide[1] }, (err, aa) => {
        // Check if the id is a valid ID
            if (!aa) {
                console.log("wrong aa");
            }else{
                total_mw += aa.mw;
            } 
            return total_mw;
      });
    }
    var publicAPI = {                           
        mw: calculate_mw                
    };
    return  publicAPI; 
}
var fred = csnotebook();
var totalmw = fred.mw("Ala-Cys");
console.log(totalmw);
I assume i can find the corresponding value mw from database, but totalmw, I always get undefined for some reson, anybody know why? Thank you!!
 
    