pan7nikt

trojkaty.js

Nov 22nd, 2021 (edited)
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var polewynik = document.getElementById("wynik");
  2.  
  3. function oblicz()
  4. {
  5.     var a = Number(document.getElementById("a").value);
  6.     var b = Number(document.getElementById("b").value);
  7.     var c = Number(document.getElementById("c").value);
  8.    
  9.     var typy = document.getElementsByName("trojkat");
  10.     var wynik = 0;
  11.    
  12.     if(typy[0].checked)
  13.     {
  14.         if(a==b && b==c && a>0 && b>0 && c>0)
  15.         {
  16.             wynik = (a*a*Math.sqrt(3))/2;
  17.             //debug
  18.             //polewynik.innerHTML = a.toString() + b.toString() + c.toString() + "1" + "Wynik: " + wynik.toString();
  19.             polewynik.innerHTML = wynik.toString();
  20.         }
  21.         else
  22.         {
  23.             polewynik.innerHTML = "taki trójkąt nie istnieje";
  24.         }
  25.     }
  26.     else if(typy[1].checked)
  27.     {
  28.         if(a>0 && b>0 && c>0)
  29.         {
  30.             if(a^2 + b^2 == c^2 || a^2 + c^2 == b^2 || c^2 + b^2 == a^2)
  31.             {
  32.                 wynik = a+b+c;
  33.                 //debug
  34.                 //polewynik.innerHTML = a.toString() + b.toString() + c.toString() + "2" + "Wynik: " + wynik.toString();
  35.                 polewynik.innerHTML = wynik.toString();
  36.             }
  37.             else
  38.             {
  39.                 polewynik.innerHTML = "taki trójkąt nie istnieje";
  40.             }
  41.         }
  42.         else
  43.         {
  44.             polewynik.innerHTML = "taki trójkąt nie istnieje";
  45.         }
  46.     }
  47.     else
  48.     {
  49.         polewynik.innerHTML = "Nie wybrano rodzaju trójkąta";
  50.     }
  51. }
  52. // https://app.diagrams.net/
Add Comment
Please, Sign In to add comment