Frezi2005

Pole Trapezu

Mar 30th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Title</title>
  6. </head>
  7. <body>
  8. <html lang="pl">
  9.  
  10. <head>
  11. <title>Pole trapezu</title>
  12. </head>
  13.  
  14. <body>
  15. Podstawa A: <input type="number" id="basisAInput"/>
  16. Podstawa B: <input type="number" id="basisBInput"/>
  17. Wysokość: <input type="number" id="heightInput"/><br>
  18. <button id="calculate">Oblicz</button><br>
  19. Wynik: <div id="result"></div>
  20.  
  21. <script>
  22.  
  23. var basisA;
  24. var basisB;
  25. var height;
  26. var resultDiv = document.querySelector("#result");
  27. var calculateBtn = document.querySelector("#calculate");
  28. var field;
  29.  
  30. calculateBtn.addEventListener('click', function() {
  31. basisA = document.querySelector("#basisAInput").value;
  32. basisB = document.querySelector("#basisBInput").value;
  33. height = document.querySelector("#heightInput").value;
  34. });
  35.  
  36. field = ((basisA + basisB)*height)/2;
  37.  
  38. calculateBtn.addEventListener("click", function() {
  39. basisA = document.querySelector("#basisAInput").value;
  40. basisB = document.querySelector("#basisBInput").value;
  41. height = document.querySelector("#heightInput").value;
  42.  
  43. if(basisA == "" || basisB == "" || height == "") {
  44. resultDiv.innerHTML = "Musisz coś wpisać";
  45. } else {
  46. resultDiv.innerHTML = field + " cm²";
  47. }
  48.  
  49. });
  50.  
  51. </script>
  52.  
  53. </body>
  54.  
  55. </html>
Advertisement
Add Comment
Please, Sign In to add comment