-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhomework1.js
More file actions
44 lines (40 loc) · 1.29 KB
/
homework1.js
File metadata and controls
44 lines (40 loc) · 1.29 KB
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
function task1() {
let num = prompt('Введите число');
let system = prompt('Введите систему счисления');
if (parseInt(num) > 0 && parseInt(system) > 1 && parseInt(system) < 10){
let strRes = '';
num = parseInt(num);
system = parseInt(system);
while(num >= system){
strRes += num % system;
num = Math.floor(num / system);
}
strRes += num;
strRes = strRes.split('').reverse().join('');
let result = 'Результат: ' + parseInt(strRes)
alert(result)
}
else{
alert('Некорректный ввод!');
}
}
function task2() {
let num1 = prompt('Введите первое число');
if (parseInt(num1)){
let num2 = prompt('Введите второе число');
if(parseInt(num2)){
num1 = parseInt(num1);
num2 = parseInt(num2);
let result = 'Ответ: ' + (num1 + num2) + ',' + (num1 / num2);
return result;
}
else{
alert('Некорректный ввод!');
}
}
else{
alert('Некорректный ввод!');
}
}
task1()
console.log(task2())