-1
I’m having an error in my course exercise someone can help me?
(function(){
var mes = prompt("Deseja calcular quantos meses? [0 à 3]");
mes = parseFloat(mes);
if(mes === 1){
function mes1(P,I){
montante1 = 'S = ' + P(1 + I);
return montante;
}
}
else if(mes === 2){
function mes2(P,I){
montante2 = 'S = ' + P(1 + I)*(1 + I);
return montante;
}
}
else if(mes === 3){
function mes3(P,I){
montante3 = 'S = ' + P(1 + I)*(1 + I)*(1 + I);
return montante;
}
}
var P = prompt("Digite a principal: ");
var I = prompt("Digite a taxa de juros: ");
var montantemes1 = mes1(P,I);
var montantemes2 = mes2(P,I);
var montantemes3 = mes3(P,I);
document.write(montantemes1);
document.write(montantemes2);
document.write(montantemes3);
})()
What error? Could you elaborate a [mcve]? And [Edit] the question describing in words what the code should do? You define functions within conditionals, but call them independent of the condition, which makes no sense; if
mes
value 1, only the functionmes1
will be defined, but even so you call at the end the functionsmes2
andmes3
. Why?– Woss
The error is the following appears the Alert but it does not show the result so the mes2 and mes3 it is the other calculation of interest if the user type 2 or 3. Can I assign the same condition in three or more functions as I did?? if not I already know that the problem was this but if yes the problem is another! Thanks for the attention
– html5