how to use variable(value) anywhere in function in javascript :  

    Below there if part of my javascript function. In that function, i am trying to  use mathematical formula:
    if(m == 1){
         var intAmt = amt * (Math.pow((1 +  rate / (12*100)), 12*period)) - amt;
         var notPaid = Math.round(parseInt(amt) + intAmt,2);
    }else if(status === "Not Paid"){
   

    //dueAmt is tobe taken from below
         var intAmt = dueAmt * (Math.pow((1 +  rate / (12*100)), 12*period)) -dueAmt;
	     var notPaid =  parseInt(dueAmt) + parseInt(amt) + intAmt;
    }
    //dueAmt is passed to the formula again n again
    var	dueAmt = notPaid; 

    the above part of code is javascript function is in for loop

    
I need to use the dueAmt variable again in if loop.But in else part of the loop it gives me undefined.