Skip to content

Commit

Permalink
feat(radical-simplifier): put operand input first
Browse files Browse the repository at this point in the history
  • Loading branch information
Eejit43 committed Dec 27, 2023
1 parent b8d6cd4 commit 4ead66b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/public/scripts/pages/tools/radical-simplifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ declare global {
}
}

const operandInput = document.querySelector('#operand') as HTMLInputElement;
const indexInput = document.querySelector('#index') as HTMLInputElement;
const radicandInput = document.querySelector('#radicand') as HTMLInputElement;
const operandInput = document.querySelector('#operand') as HTMLInputElement;
const simplifyButton = document.querySelector('#simplify') as HTMLButtonElement;
const resetButton = document.querySelector('#reset') as HTMLButtonElement;
const output = document.querySelector('#output') as HTMLSpanElement;
const message = document.querySelector('#message') as HTMLSpanElement;

for (const event of ['input', 'paste']) {
operandInput.addEventListener(event, () => (operandInput.value = operandInput.value.replaceAll(/\D/g, '')));
indexInput.addEventListener(event, () => (indexInput.value = indexInput.value.replaceAll(/\D/g, '')));
radicandInput.addEventListener(event, () => (radicandInput.value = radicandInput.value.replaceAll(/[^\d-]/g, '').replaceAll(/(?<!^)-/g, '')));
operandInput.addEventListener(event, () => (operandInput.value = operandInput.value.replaceAll(/\D/g, '')));
}

for (const input of [indexInput, radicandInput, operandInput]) input.addEventListener('keydown', (event) => (event.key === 'Enter' ? simplifyButton.click() : null));
Expand All @@ -35,8 +35,8 @@ simplifyButton.addEventListener('click', () => {
message.textContent = '';
output.classList.remove('hidden');

const index = indexInput.value ? Number.parseInt(indexInput.value) : 2;
const operand = operandInput.value ? Number.parseInt(operandInput.value) : 1;
const index = indexInput.value ? Number.parseInt(indexInput.value) : 2;
const originalRadicand = Number.parseInt(radicandInput.value);
const negativeRadicand = originalRadicand < 0;

Expand Down Expand Up @@ -85,9 +85,9 @@ simplifyButton.addEventListener('click', () => {
resetButton.addEventListener('click', () => {
message.textContent = 'Nothing yet!';
output.classList.add('hidden');
operandInput.value = '';
indexInput.value = '';
radicandInput.value = '';
operandInput.value = '';
showAlert('Reset!', 'success');
});

Expand Down
8 changes: 4 additions & 4 deletions src/views/pages/tools/radical-simplifier.hbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<section>
<h2>Input (<span class="code">\(operand \cdot \sqrt[index]{radicand}\)</span>):</h2>
<div>
Operand:
<input id="operand" placeholder="1" />
</div>
<div>
Index:
<input id="index" placeholder="2" />
Expand All @@ -8,10 +12,6 @@
Radicand:
<input id="radicand" />
</div>
<div>
Operand:
<input id="operand" placeholder="1" />
</div>

<button id="simplify">Simplify</button>
<button id="reset" class="button-danger">Reset</button>
Expand Down

0 comments on commit 4ead66b

Please sign in to comment.