Acredito que queira isso: <!-- begin snippet: js hide: false console: true babel: false --> <!-- language: lang-html --> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Exercicio1</title> <script> function caculoCompra(total,parcelas){ var resul=total; if(parcelas==1){ resul=total; } else if(parcelas==2){ resul+=(total*0.3)/100; } else{ resul+=(total*0.7)/100; } return resul; } window.onload = function(){ var btn = document.getElementById("btn"); btn.onclick = function (){ var resp; var valor = parseInt(document.getElementById("valor").value); var parcelas = parseInt(document.getElementById("parcelas").value); resp=caculoCompra(valor,parcelas); alert("O valor final é " + resp); } } </script> </head> <body> <h2>Exercicio 1</h2> <form name="form1" id="form1" method="post" action="" > Informe o valor <input name="login" type="text" id="valor" size="15"> <br> Informe o numero de parcelas <input name="senha" type="text" id="parcelas" size="10"> <br> <input type="button" name="button" id="btn" value="OK"> </form> </body> </html> <!-- end snippet -->