Guest User

Rechner

a guest
Sep 27th, 2020
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 3.08 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
  5. </head>
  6. <body>
  7.     <form class="col-lg-6 offset-lg-3">
  8.         <h1>Rechner</h1>
  9.         <div class="form-group">
  10.             <label for="income">Netto-Einkommen</label>
  11.             <input id="income" class="form-control" type="text" value="30000" name="einkommen" autocomplete="off">
  12.         </div>
  13.         <div class="form-group">
  14.             <label for="expenses">Ausgaben pro Jahr</label>
  15.             <input id="expenses" class="form-control" type="text" value="12000" name="ausgaben" autocomplete="off">
  16.         </div>
  17.         <div class="form-group">
  18.             <label for="savings">Sparbetrag pro Jahr</label>
  19.             <input id="savings" class="form-control" type="text" value="18000" name="sparrate" autocomplete="off">
  20.         </div>
  21.         <div class="form-group">
  22.             <label for="networth">Aktuelles Vermögen</label>
  23.             <input id="networth" class="form-control" type="text" value="0" name="vermoegen" autocomplete="off">
  24.         </div>
  25.         <div class="form-group">
  26.             <label for="roi">Jährliche Rendite</label>
  27.             <input id="roi" class="form-control" type="text" value="5" name="rendite" autocomplete="off">
  28.         </div>
  29.         <div class="form-group">
  30.             <label for="withdrawal-rate">Entnahmerate</label>
  31.             <input id="withdrawal-rate" class="form-control" type="text" value="4" name="withdrawal" autocomplete="off">
  32.         </div>
  33.         <input type="button" value="Berechnen">
  34.  
  35.         <br><br>
  36.         <p id="output"></p>
  37.     </form>
  38.    
  39.     <script type="text/javascript">
  40.         const button = document.querySelector('input[type="button"]');
  41.         const output = document.querySelector('p#output');
  42.  
  43.         button.addEventListener('click', calculate);
  44.  
  45.         function calculate() {
  46.             var income = document.getElementById('income').value;
  47.             var expenses = document.getElementById('expenses').value;
  48.             var savings = document.getElementById('savings').value;
  49.             var networth = document.getElementById('networth').value;
  50.             var roi = document.getElementById('roi').value / 100;
  51.             var withdrawalrate = document.getElementById('withdrawal-rate').value / 100;
  52.  
  53.             var savingrate = (income - expenses) / income;
  54.        
  55.             if(withdrawalrate == 0 || savingrate == 0) {
  56.                 output.textContent = 'So wird das nichts...';
  57.             }
  58.             else {
  59.                 var years =  Math.log((((roi * (1 - savingrate) * income) / withdrawalrate) + (savingrate * income)) / ((roi * networth) + (savingrate * income))) / Math.log(1 + roi);
  60.            
  61.                 var years_string = Math.round(years *10)/10;
  62.                 var savingrate_string = Math.round(savingrate*100)+'%'
  63.  
  64.                 output.textContent = 'Du kannst in Rente gehen in '+years_string+' Jahren bei einer Sparquote von '+savingrate_string+'.';
  65.             }
  66.         }
  67.     </script>
  68. </body>
  69. </html>
Add Comment
Please, Sign In to add comment