-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculations_script.js
46 lines (46 loc) · 1.48 KB
/
calculations_script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
function calculations() {
// document.getElementById('demo').innerHTML = 'Теперь посчитали.';
// alert('Просто alert');
// prompt('Задайте два числа и действие', 0);
// confirm('Теперт confirm');
var number1 = Number(prompt('первое число', 0));
var action = String(prompt('действие: + - * / %', 0));
var number2 = Number(prompt('второе число', 0));
// alert('Наши расчеты: number1')
var result;
result = (action == '+') ? number1 + number2 : (action == '-') ? number1 - number2 : (action == '*') ? number1 * number2 :
(action == '/') ? number1 / number2 : (action == '%') ? number1 % number2 : 'something else.'
/*if (action == '+')
{
result = number1 + number2
}
else if (action == '-')
{
result = number1 - number2;
}
else if (action == '*')
{
result = number1 * number2
}
else if (action == '/')
{
if (number2 == 0)
{
result = 'Devision by zero.'
}
else
result = number1 / number2
}
else if (action == '%')
{
if (number2 == 0)
{
result = 'Devision by zero.'
}
else
result = number1 % number2
}
else
result = 'Действие не определено.'*/
document.getElementById('demo').innerHTML = number1 + ' ' + action + ' ' + number2 + ' = ' + result + ' ';
}