-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
155 lines (113 loc) · 3.61 KB
/
script.js
File metadata and controls
155 lines (113 loc) · 3.61 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
// Основное задание
function startGameOne() {
const randomNumber = Math.floor(Math.random() * 100) + 1;
let guessedCorrectly = false;
alert("Привет! Начинаем игру 'Угадай Число'.\nЯ загадал число от 1 до 100.");
while (!guessedCorrectly) {
let userInput = prompt("Введи свое предположение (число от 1 до 100). Если хочешь сдаться, нажми 'Отмена'.");
if (userInput === null) {
alert('Игра окончена.');
return;
}
const userGuess = parseInt(userInput);
if (isNaN(userGuess)) {
alert('Ошибка! Введи целое число.');
continue;
}
if (userGuess < 1 || userGuess > 100) {
alert("Число должно быть в диапазоне от 1 до 100. Попробуй еще раз.");
continue;
}
if (userGuess < randomNumber) {
alert(`Загаданное число БОЛЬШЕ, чем ${userGuess}. Попробуй еще!`);
} else if (userGuess > randomNumber) {
alert(`Загаданное число МЕНЬШЕ, чем ${userGuess}. Попробуй еще!`);
} else {
guessedCorrectly = true;
alert(`🎉 Поздравляю! Ты угадал! Загаданное число было ${randomNumber}.`);
}
}
}
// Задание 1
function findSmallNum(num1, num2) {
if (num1 < num2) {
return num1;
} else {
return num2;
}
}
findSmallNum(8, 4)
// Задание 2
function checkEvenOdd(number) {
if (number % 2 === 0) {
return 'Число четное';
} else {
return 'Число нечетное';
}
}
checkEvenOrOdd(4)
// Задание 3
function squareNum(number) {
const square = number * number;
console.log(`Квадрат числа ${number} равен ${square}`);
}
squareNum(5);
// Задание 4
function checkUserAge() {
const ageString = prompt("Сколько вам лет?");
if (ageString === null) {
alert("Ввод был отменен.");
return;
}
const age = parseInt(ageString);
if (age < 0) {
alert('Вы ввели неправильное значение');
}
else if (age >= 0 && age <= 12) {
alert('Привет, друг!');
}
else if (age >= 13) {
alert('Добро пожаловать!');
}
else {
alert('Вы ввели неправильное значение');
}
}
checkUserAge();
// Задание 5
function multiplyIfNumbers(param1, param2) {
const num1 = Number(param1);
const num2 = Number(param2);
if (isNaN(num1) || isNaN(num2)) {
return 'Одно или оба значения не являются числом';
} else {
return num1 * num2; [[1]]
}
}
multiplyIfNumbers(3, 4);
// Задание 6
function numberCube() {
const userInput = prompt("Пожалуйста, введите число:");
const number = Number(userInput);
if (isNaN(number)) {
return 'Переданный параметр не является числом';
} else {
const cubedNum = number * number * number;
return `${number} в кубе равняется ${cubedNum}`;
}
}
numberCube();
// Задание 7
function createCircle(radius) {
const circle = {
radius: radius,
getArea: function() {
return Math.PI * this.radius * this.radius;
},
getPerimeter: function() {
return 2 * Math.PI * this.radius;
}
};
return circle;
}
createCircle();