Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/components/Keyboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const keyboardButtons = {
{ label: '7', gridArea: 'seven' },
{ label: '8', gridArea: 'eight' },
{ label: '9', gridArea: 'nine' },
{ label: 'x', value: '*', gridArea: 'multiply' },
{ label: 'x', value: 'x', gridArea: 'multiply' },
{ label: '4', gridArea: 'four' },
{ label: '5', gridArea: 'five' },
{ label: '6', gridArea: 'six' },
Expand Down Expand Up @@ -63,9 +63,10 @@ function Keyboard() {
const calc: Calc = {
basic: () => {
try {
const replaceResult = calcValue.basic.replace(/\x/g, '*');
return {
inputs: [calcValue.basic],
results: [math.evaluate(calcValue.basic)]
results: [math.evaluate(replaceResult)]
};
} catch (error) {
return {
Expand Down Expand Up @@ -170,8 +171,10 @@ function Keyboard() {

const targetButton = buttonRefs.current.find(button => {
if (value === ' ') return button?.value === ',';
if (value === '*') return button?.value === 'x';
return button?.value === value;
});

targetButton?.classList.add('active');
};

Expand All @@ -185,6 +188,7 @@ function Keyboard() {
}
const targetButton = buttonRefs.current.find(button => {
if (value === ' ') return button?.value === ',';
if (value === '*') return button?.value === 'x';
return button?.value === value;
});
targetButton?.classList.remove('active');
Expand Down