I think I have missunderstod the syntax, I need a [generic energy drink]. It returns the same value.
var tal1 = antalAr(1000000,1000);
document.writeln("A loan of 1000000 SEK is paid after " +
Math.ceil(answer) + " years if the installment is 1000kr/mån.");
var tal2 = antalAr(1500000,500);
document.writeln("A loan of 1500000 SEK is paid after " +
Math.ceil(answer) + " years if the installment is 500kr/mån.");
function antalAr(lan, amortering)
{
amoyear = amortering * 12;
for( var answer = 1; amoyear * answer <= loan; answer++){}
return answer;
}
answer is only declared in the local function scope in antalAr(). You can’t use it outside the function.
try this:
edit: oh, a typo as well