hw08_16_!CalcLive.html 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // отправка с уведомлением//
  2. <head>
  3. <h1>CalcLive</h1>
  4. </head>
  5. <body>
  6. <div>
  7. <input id="testimony1" type="number" size="12" placeholder="0" />//вносим показания старта периода//<br>
  8. <input id="testimony2" type="number" size="12" placeholder="0" />//вносим показания учета на конец
  9. периода//<br>
  10. <input id="tarif" type="number" size="12" placeholder="0" />//вводим тариф на услугу//<br>
  11. <input id="startbalance" type="number" size="12" placeholder="0" />//вводим баланс на старте
  12. периода//<br>
  13. <!--<button onclick="debetCalculationOnClick()"> //нажимаем на кнопку для расчета//
  14. DEBET Calc
  15. </button>-->
  16. <br><br>
  17. <div id="calc" style="display: inline-block;color:greenyellow;"></div>
  18. <script>
  19. const debetCalculation = (testimony1, testimony2, tarif, startbalance) =>
  20. result = startbalance - (testimony2 - testimony1) * tarif;
  21. const debetCalculationOnClick = () => {
  22. testimony1Val = parseFloat(testimony1.value);
  23. testimony2Val = parseFloat(testimony2.value);
  24. tarifVal = parseFloat(tarif.value);
  25. startbalanceVal = parseFloat(startbalance.value);
  26. result = debetCalculation(testimony1Val, testimony2Val, tarifVal, startbalanceVal);
  27. calc = document.getElementById('calc');
  28. calc.innerHTML = result.toString();
  29. if (result > 0) {
  30. calc.style.backgroundColor = 'green';
  31. calc.innerHTML = "Total Amount: " + calc.innerHTML;
  32. }
  33. else if (isNaN(result))
  34. calc.innerHTML = "";
  35. else {
  36. calc.style.backgroundColor = 'red';
  37. }
  38. }
  39. testimony1.oninput = debetCalculationOnClick;
  40. testimony2.oninput = debetCalculationOnClick;
  41. tarif.oninput = debetCalculationOnClick;
  42. startbalance.oninput = debetCalculationOnClick;
  43. </script>
  44. </div>
  45. </body>