Показать сообщение отдельно
  #2 (permalink)  
Старый 01.04.2017, 00:04
Аватар для рони
Профессор
Отправить личное сообщение для рони Посмотреть профиль Найти все сообщения от рони
 
Регистрация: 27.05.2010
Сообщений: 33,103

maks_Kraevoj,
<!DOCTYPE html>

<html>
<head>
  <title>Untitled</title>
  <meta charset="utf-8">


</head>

<body>

  <script>
window.addEventListener("DOMContentLoaded", function() {

        !function calculator() {


            function add(a, b) {
                return a + b;
            }

            function sub(a, b) {
                return a - b;
            }

            function mul(a, b) {
                return a * b;
            }

            function div(a, b) {
                return a / b;
            }

            var operand1 = prompt("Введите первое число: ");
            var sign = prompt("Введите знак арифметической операции: + - * /");
            var operand2 = prompt("Введите второе число: ");
            var result, html = "<p><b style='color:red'>" + sign + "</b> - не является знаком арифметической операции.";

            operand1 = parseInt(operand1);
            operand2 = parseInt(operand2);

            switch (sign) {
                case "+":
                    result = add(operand1, operand2);
                    break;
                case "-":
                    result = sub(operand1, operand2);
                    break;
                case "*":
                    result = mul(operand1, operand2);
                    break;
                case "/":
                    result = div(operand1, operand2);
                    break;

                default:
                   result = null
            }
          if(result !== null) html = "<p>" + operand1 + " " + sign + " " + operand2 + " = " + result;
          document.body.insertAdjacentHTML("beforeEnd", html);
           setTimeout(calculator, 5000);

        }()



});
  </script>

</body>
</html>
Ответить с цитированием