Advertisement
Guest User

zad3a

a guest
Oct 20th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. <html>
  2. <head lang="pl">
  3. <meta charset="UTF-8">
  4. </head>
  5. <body>
  6.  
  7. Podaj boki prostopadłościanu:
  8. <form>
  9.  
  10. Bok a: <input type="text" id="a" name="a"/>
  11. Bok b: <input type="text" id="b" name="b"/>
  12. Bok h: <input type="text" id="h" name="h"/>
  13. <br/><input type="button" id="button" value="Wyślij"></input>
  14.  
  15. </form>
  16. <div id="output"></div>
  17.  
  18. <script>
  19. function obliczenia(){
  20. var a=document.getElementById('a');
  21. var b=document.getElementById('b');
  22. var h=document.getElementById('h');
  23. var wynik;
  24.  
  25. if(a.value.length==0)
  26. {
  27.  
  28.  
  29. output.innerHTML=("Pole z wartością A nie może być puste");
  30. }
  31. else if (b.value.length==0)
  32. {
  33. output.innerHTML=("Pole z wartością B nie może być puste");
  34.  
  35. }
  36. else if (h.value.length==0)
  37. {
  38. output.innerHTML=("Pole z wartością H nie może być puste");
  39.  
  40. }
  41. else if(isNaN(a.value) || isNaN(b.value) || isNaN(h.value))
  42. {
  43.  
  44. output.innerHTML=("Pola muszą zawierać liczby!");
  45. }
  46. else if(0>a.value || 0>b.value || 0>h.value)
  47. {
  48. output.innerHTML=("Wartości muszą być większe od 0!")
  49. }
  50. else
  51. {
  52.  
  53. wynik=Math.sqrt(a.value*a.value+b.value*b.value+h.value*h.value);
  54.  
  55. output.innerHTML=("Przekątna prostopadłościanu wynosi: "+wynik);
  56. }
  57. }
  58. button.onclick=function(){
  59.  
  60. obliczenia();
  61. return false;
  62.  
  63.  
  64. }
  65. </script>
  66.  
  67. </body>
  68.  
  69.  
  70. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement