It is required to make a simple calculator using only HTML5 and JS (without CSS).

I have the following question: How to create a "output window"? The code has two input fields and an operator ( + , - , * , / ).

 function calc() { case "+": console.log(A + B); break; case "-": console.log(A - B); break; case "*": console.log(A * B); break; case "/": console.log(A / B); break; } calc(); document.write(calc); 
 <input type="number" value="0" id="A"> <br> <select id="operator"> <option value="+">+</option> <option value="-">-</option> <option value="*">*</option> <option value="/">/</option> </select> <br> <input type="number" value="0" id="B"> <br> <button value="calc">Calc</button> <br> 

  • This is a Russian site. For the future: do not duplicate the question in English. - eanmos
  • Thank you, I will consider. I thought it would be more correct. - Uri Shlomy

1 answer 1

In js there are basic UI operations: alert , prompt and confirm , which allow you to work with data received from the user.

An alert will suit you, you can use it instead of console.log . It will display a window with a message and suspend the execution of the script until the user clicks OK .

  • kizoso, thank you. If I understood correctly, then "alert" displays a message in a separate window and requires pressing the "OK" button to continue the next calculation. Can I output the result directly to output? - Uri Shlomy
  • ru.stackoverflow.com/questions/512487/… - found a similar question - 3 output options, including output - kizoso
  • Fine! what the doctor ordered! thanks (-; - Uri Shlomy