-
Notifications
You must be signed in to change notification settings - Fork 103
6212_КозленкоЕИ_Лаб. 4 #424
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…ораторных 1,2 и на калькулятор
mxwrlld
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
calculator.js
Outdated
| if (!errorMessage) { | ||
| // Форматируем результат | ||
| const formattedResult = parseFloat(result.toFixed(10)); | ||
| resultElement.textContent = formattedResult; | ||
| resultElement.className = 'success'; | ||
|
|
||
| // Показываем информацию о вычислении | ||
| calculationInfo.textContent = `${num1} ${operationSymbol} ${num2} = ${formattedResult}`; | ||
|
|
||
| // Добавляем небольшую анимацию к результату | ||
| resultElement.style.transform = 'scale(1.1)'; | ||
| setTimeout(() => { | ||
| resultElement.style.transform = 'scale(1)'; | ||
| }, 300); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Лучше выделить в отдельную функцию
| let result; | ||
| let operationSymbol = ''; | ||
| let errorMessage = ''; | ||
|
|
||
| // Выполняем выбранную операцию | ||
| switch(operation) { | ||
| case 'add': | ||
| result = num1 + num2; | ||
| operationSymbol = '+'; | ||
| break; | ||
| case 'subtract': | ||
| result = num1 - num2; | ||
| operationSymbol = '-'; | ||
| break; | ||
| case 'multiply': | ||
| result = num1 * num2; | ||
| operationSymbol = '×'; | ||
| break; | ||
| case 'divide': | ||
| // Проверка деления на ноль | ||
| if (num2 === 0) { | ||
| errorMessage = 'Деление на ноль невозможно'; | ||
| resultElement.textContent = 'Ошибка: Деление на ноль'; | ||
| resultElement.className = 'error'; | ||
| calculationInfo.textContent = errorMessage; | ||
| highlightInputError(num2Input); | ||
| showHintError(hint2, 'Нельзя делить на ноль'); | ||
| return; | ||
| } | ||
| result = num1 / num2; | ||
| operationSymbol = '÷'; | ||
| break; | ||
| default: | ||
| errorMessage = 'Неизвестная операция'; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Лучше выделить в отдельную функцию.
Также ошибка деления на ноль и неизвестной операции обрабатываются по - разному.
Также ошибка неизвестной операции никогда не отобразится, поскольку для неё if (!errorMessage) всегда false
|
Зачтено! |
…ораторных 1,2 и на калькулятор