Skip to content

Instantly share code, notes, and snippets.

@danielbonifacio
Created July 21, 2017 14:50
Show Gist options
  • Save danielbonifacio/8c88a59f3dff4a48d288a4ab4f61128f to your computer and use it in GitHub Desktop.
Save danielbonifacio/8c88a59f3dff4a48d288a4ab4f61128f to your computer and use it in GitHub Desktop.
Calculadora de juros composto em jQuery
<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>
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