Skip to content

Лаб. 1 6411 Панявкин Андрей#107

Open
zaRT0 wants to merge 2 commits intoitsecd:mainfrom
zaRT0:lab_1
Open

Лаб. 1 6411 Панявкин Андрей#107
zaRT0 wants to merge 2 commits intoitsecd:mainfrom
zaRT0:lab_1

Conversation

@zaRT0
Copy link

@zaRT0 zaRT0 commented Feb 27, 2026

No description provided.

@zaRT0 zaRT0 marked this pull request as draft February 27, 2026 18:31
@zaRT0 zaRT0 marked this pull request as ready for review February 27, 2026 18:33
@AvtoBBus AvtoBBus self-requested a review February 28, 2026 10:22
Copy link
Collaborator

@AvtoBBus AvtoBBus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Небольшие правки

Comment on lines +9 to +33
function validateInput(input) {
let value = input.value.replace(/[^0-9.\-]/g, '');

if (value.length > 0 && value[0] !== '-') {
value = value.replace(/\-/g, '');
} else if (value.length > 1) {
value = '-' + value.substring(1).replace(/\-/g, '');
}

const dots = value.match(/\./g);
if (dots && dots.length > 1) {
const parts = value.split('.');
value = parts[0] + '.' + parts.slice(1).join('').replace(/\./g, '');
}

if (/^[+*/]/.test(value)) {
value = value.substring(1);
}

if (value.startsWith('.')) {
value = '0' + value;
}

return value;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это слишком сложно и не нужно, просто поставьте у input атрибут type="number"

Comment on lines +3 to +7
const firstNumberInput = document.getElementById('firstNumber');
const secondNumberInput = document.getElementById('secondNumber');
const operatorSelect = document.getElementById('operator');
const calculateBtn = document.getElementById('calculateBtn');
const resultContainer = document.getElementById('resultContainer');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Какой-то элемент может быть не найден (мало ли что произошло)

Comment on lines +47 to +52
input.addEventListener('keypress', function(e) {
const char = String.fromCharCode(e.which);
if (!/[0-9.\-]/.test(char)) {
e.preventDefault();
}
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Опять же лишние действия, просто тип number нужен

Comment on lines +154 to +160
[firstNumberInput, secondNumberInput].forEach(input => {
input.addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
calculate();
}
});
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Похожий код был выше, можно все назначения слушателей событий повесить в одном forEach

Comment on lines +63 to +80
if (!firstValue && !secondValue) {
firstNumberInput.classList.add('error');
secondNumberInput.classList.add('error');
showError('Введите оба числа');
return;
}

if (!firstValue) {
firstNumberInput.classList.add('error');
showError('Введите первое число');
return;
}

if (!secondValue) {
secondNumberInput.classList.add('error');
showError('Введите второе число');
return;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно упросить

if (!firstValue || !secondValue)
{
    let errorText = `Введите ${!firstValue ? 'первое' : 'второе'} число`;
    if (!firstValue && !secondValue)
        errorText = 'Введите  оба числа';

    if (!firstValue) firstNumberInput.classList.add('error');
    if (!secondValue) secondNumberInput.classList.add('error');

    showError(errorText);
    return
}

Comment on lines +120 to +121
result = num1 / num2;
result = Math.round(result * 1000000) / 1000000;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

result.toFixed(6)

}
}

html += `<div class="result-item success">${calculationHistory[calculationHistory.length - 1]}</div>`;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Скорее не success, а current

Comment on lines +139 to +149
let html = '';

if (calculationHistory.length > 1) {
for (let i = 0; i < calculationHistory.length - 1; i++) {
html += `<div class="result-item">${calculationHistory[i]}</div>`;
}
}

html += `<div class="result-item success">${calculationHistory[calculationHistory.length - 1]}</div>`;

resultContainer.innerHTML = html;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В целом и так хорошо, но лично я бы этот код написал бы так

resultContainer.innerHtml = calculationHistory.map((item, index) => {
    const checkLast = index === calculationHistory.length - 1;
    return `<div class="result-item ${checkLast ? 'current' : ''}">${item}</div>`
})

Comment on lines +32 to +34
<div class="result-container" id="resultContainer">
<div class="result-item" style="opacity: 0.5; font-style: italic;">Результат появится здесь</div>
</div>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Чтобы не писать inline-стили можно просто поменять класс

<div class="result-container" id="resultContainer">
     <div class="result-container__placeholder">Результат появится здесь</div>
 </div>
.result-container__placeholder {
    opacity: 0.5;
    font-style: italic;
}

Comment on lines +81 to +90
.operator-wrapper::after {
content: '▼';
position: absolute;
right: 12px;
top: 50%;
transform: translateY(-50%);
color: #c95b5b;
font-size: 10px;
pointer-events: none;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Уважаемо

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants