Created
July 21, 2017 14:50
-
-
Save danielbonifacio/8c88a59f3dff4a48d288a4ab4f61128f to your computer and use it in GitHub Desktop.
Calculadora de juros composto em jQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="meuApp"> | |
<label for="capital">Capital</label> | |
<input type="number" id="capital" placendolder="Capital"> | |
<label for="capital">Taxa de juros</label> | |
<input type="number" id="capital" placendolder="Taxa de juros"> | |
<label for="capital">Tempo de aplicação</label> | |
<input type="number" id="capital" placendolder="Tempo Aplicação"> | |
<!-- Botão para chamar a func --> | |
<button type="button" onclick="calculaJuros()">Calcular</button> | |
<hr> | |
<input type="text" id="total"> | |
<input type="text" id="mensal"> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function calculaJuros(){ | |
//Captura dos valores dos inputs e declaração de variáveis | |
var capital = $('#capital').val(); | |
var taxaJuros = $('#taxaJuros').val(); | |
var tempoAplicacao = $('#tempoAplicacao').val(); | |
//Vamos dividir a taxa de juros por 100 | |
var taxaJuros = taxaJuros/100; | |
//Com as variáveis criadas e definidas, tá na hora da gente definer o montante, usando as variáveis acima | |
var montante = capital * Math.pow((1 + taxaJuros), tempoAplicacao); | |
//Agora é mamão com açúcar! Basta definir o valor total, na var tot e o valor mensal na var men. | |
var tot = montante.toString(); //Converte o total para string | |
var men = tot/tempoAplicacao; //Quanto pago mensalmente? | |
//Bora exibir isso em alguns inputs na página | |
$('#total').val(tot); | |
$('#mensal').val(men); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment