Q:

Need to get simple calculation answer when action is selected from options

I have dropdown menu where I can choose an action. I need that after I select my action and put my numbers in there would be answer shown at the bottom. I created functions for each action, but I don't know how to make it work.
Also, it should show, that I can't divide if the second number is equal to 0.

<!DOCTYPE html>
<html>

 <head>
  <meta charset="utf-8">
  <link type="text/css" rel="stylesheet" href="stilius.css">
 </head>

 <body>
  <form>
   <div id="pavadinimas">
    Operacija
   </div>
 
   <label>
    <select>
     <option>Sudėtis</option>
     <option>Atimtis</option>
     <option>Daugyba</option>
     <option>Dalyba</option>
    </select>
   </label>

   <label>
    <div class="text">1 skaičius</div>
    <input id="pirmasSkaicius" type=number placeholder="Pirmas skaičius"></input>
   </label>

   <label>
    <div class="text"> 2 skaičius</div>
    <input id="antrasSkaicius" type=number placeholder="Antras skaičius"></input>
   </label>

    <b>Rezultatas:</b> 
    <span id="rezultatas"></span>
  </form>
 </body>
 
 <script>
  function sudetis(){
   1sk = document.getElementById("pirmasSkaicius").value;
   2sk = document.getElementById("antrasSkaicius").value;
   document.getElementById("rezultatas").innerHTML = 1sk + 2sk;
  }
  
  function atimtis(){
   1sk = document.getElementById("pirmasSkaicius").value;
   2sk = document.getElementById("antrasSkaicius").value;
   document.getElementById("rezultatas").innerHTML = 1sk - 2sk;
  }
  
  function daugyba(){
   1sk = document.getElementById("pirmasSkaicius").value;
   2sk = document.getElementById("antrasSkaicius").value;
   document.getElementById("rezultatas").innerHTML = 1sk * 2sk;
  }
  
  function dalyba(){
   1sk = document.getElementById("pirmasSkaicius").value;
   2sk = document.getElementById("antrasSkaicius").value;
   document.getElementById("rezultatas").innerHTML = 1sk / 2sk;
  }
 </script>
</html>

A:

Here is a working version of the snippet. First off, js variables cannot start with a number so I changed 1sk to sk1 and the same for 2sk. I have added a button that needs to be clicked for the results to be shown. Furthermore, I have fused all the functions together. You can take a look and let me know if there is anything that is unclear.

<!DOCTYPE html>
<html>

 <head>
  <meta charset="utf-8">
  <link type="text/css" rel="stylesheet" href="stilius.css">
 </head>

 <body>
  <form>
   <div id="pavadinimas">
    Operacija
   </div>
 
   <label>
    <select id="operacija">
     <option value="sudetis">Sudėtis</option>
     <option value="atimtis">Atimtis</option>
     <option value="daugyba">Daugyba</option>
     <option value="dalyba">Dalyba</option>
    </select>
   </label>

   <label>
    <div class="text">1 skaičius</div>
    <input id="pirmasSkaicius" type="number" placeholder="Pirmas skaičius"></input>
   </label>

   <label>
    <div class="text">2 skaičius</div>
    <input id="antrasSkaicius" type="number" placeholder="Antras skaičius"></input>
   </label>
   <button id="calculate">calculate</button>
    <b>Rezultatas:</b> 
    <span id="rezultatas"></span>
  </form>
 </body>
 
 <script>
 
  document.getElementById("calculate").addEventListener("click", function(event){
   event.preventDefault();
   calculate();
  });
  
  function calculate(){
   var sk1 = parseFloat(document.getElementById("pirmasSkaicius").value);
   var sk2 = parseFloat(document.getElementById("antrasSkaicius").value);
   var operacija = document.getElementById("operacija").value;
   switch (operacija) {
    case 'sudetis':
     result = sk1 + sk2;
     break;
    case 'atimtis':
     result = sk1 - sk2;
     break;
    case 'daugyba':
     result = sk1 * sk2;
     break;
    case 'dalyba':
     if(sk2 != 0)
      result = sk1 / sk2;
     else
      result = "You cannot divide by zero";
     break;

   }
   document.getElementById("rezultatas").innerHTML = result;


  }
 
 </script>
</html>

