Skip to content

daniel aminov#8

Open
ItsAminov wants to merge 1 commit into
ColmanDevClubORG:mainfrom
ItsAminov:dev
Open

daniel aminov#8
ItsAminov wants to merge 1 commit into
ColmanDevClubORG:mainfrom
ItsAminov:dev

Conversation

@ItsAminov

Copy link
Copy Markdown

add initial calculator functionality with input validation and display updates

@ItsAminov ItsAminov changed the title dnaiel aminov daniel aminov Nov 29, 2025
Comment thread calculator.js
@@ -0,0 +1,51 @@
let displayText = "\xa0";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why did you use "\xa0"?

Comment thread calculator.js
const displayInvalidInputMessage = (expression, displayElement) => {
displayElement.innerText = "invalid input";

setTimeout(() => displayExpression(expression, displayElement), 500);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why timeout?

@ItsAminov ItsAminov Dec 7, 2025

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

that was my idea of how to indicate to the user that the input is invalid i display the message in the display bar and i think its more complicated to display the expression again in other ways.let me know if there is a better practice

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I see. That's fine. Consider to show permeant text (usually appears in red). But again, that's also a solid solution 💪

Comment thread calculator.js
Comment on lines +19 to +23
const processInput = (input, event) => {
if (event.target.id == "equal") return calculate(input);
else if (event.target.id == "clear") return "\xa0";
else return (input += event.target.innerText);
};

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Consider separate the handling logic.
assign the relevant function as a listener to the relevant button.

Comment thread calculator.js
};

const validateIput = (expression, newChar) => {
const ops = "+-*/";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

consider to move this constant to the global scope.
The constant is created every validateIput call.

Comment thread calculator.js

const validateIput = (expression, newChar) => {
const ops = "+-*/";
const last = expression === "\xa0" ? "" : expression.at(-1);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

is last the operation?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

its the last char that was added to the expression . it could be an operator

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