DOM1.html 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>DOM1</title>
  8. <style>
  9. .inp {
  10. margin-bottom: 10px;
  11. }
  12. </style>
  13. </head>
  14. <body>
  15. <div style="display: flex; flex-direction: column; width: 140px; margin: 0 auto; margin-bottom: 25px;">
  16. <input type="number" placeholder="breakfast calories" id="breakfast" class="inp">
  17. <input type="number" placeholder="lunch calories" id="lunch" class="inp">
  18. <input type="number" placeholder="lunch calories" id="dinner" class="inp">
  19. <input type="button" value="Calculate" id="calc">
  20. </div>
  21. <div id="res" style=" width: 25px; height: 25px; align-items:center; margin: 0 auto; padding: 1em ;">
  22. 0
  23. </div>
  24. <script>
  25. let calculator = document.getElementById("calc");
  26. let breakFa = document.getElementById("breakfast");
  27. let lunch = document.getElementById("lunch");
  28. let dinner = document.getElementById("dinner");
  29. let result = document.getElementById("res");
  30. calculator.onclick = function () {
  31. result.innerText = +breakFa.value + +lunch.value + +dinner.value;
  32. result.style.backgroundColor = "green";
  33. };
  34. function calc() {
  35. result.innerText = +breakFa.value + +lunch.value + +dinner.value;
  36. result.style.backgroundColor = '';
  37. }
  38. breakFa.oninput = calc;
  39. lunch.oninput = calc;
  40. dinner.oninput = calc;
  41. </script>
  42. <script src="/DOM1.js"></script>
  43. </body>
  44. </html>