Webbserver - Love Blomberg

Show sourcecode

The following files exists in this folder. Click to view.

public_html/gamla-kurser/webbutv2/övningar/js_villkor/

js_villkor_a.html
js_villkor_b.html
js_villkor_c.html
js_villkor_d.html
js_villkor_e.html
js_villkor_f.html

js_villkor_c.html

38 lines UTF-8 Windows (CRLF)
<!doctype html>
<html lang="sv">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Webbutv2 - Love B</title>
    <link rel="stylesheet" href="">
  </head>
  <body>
  <h1>JS Villkor C</h1>
  <h3>Mata in ditt första tal</h3>
  <input type="number" name="textruta1" id="textruta1">
  <h3>Mata in ditt andra tal</h3>
  <input type="number" name="textruta2" id="textruta2">
  <h3>Mata in ditt tredje tal</h3>
  <input type="number" name="textruta3" id="textruta3">
  <button onclick="kollaVillkor()">Klicka mig</button>
  <br><br>
  <div id="divruta"></div>
  <script>
   var textruta1 = document.getElementById("textruta1");
   var textruta2 = document.getElementById("textruta2");
   var divruta = document.getElementById("divruta");

   function kollaVillkor() {
    if ((textruta1.value > textruta2.value) && textruta1.value > textruta3.value) {
     divruta.innerHTML = textruta1.value + " är störst.";
    } else if ((textruta2.value > textruta1.value) && textruta2.value > textruta3.value) {
     divruta.innerHTML = textruta2.value + " är störst.";
    } else if ((textruta3.value > textruta1.value) && textruta3.value > textruta2.value) {
     divruta.innerHTML = textruta3.value + " är störst.";
    } else {
     divruta.innerHTML = "Det finns flera tal som är lika stora.";
    }
   }
  </script>
  </body>
</html>