daniel aminov#8
Conversation
| @@ -0,0 +1,51 @@ | |||
| let displayText = "\xa0"; | |||
| const displayInvalidInputMessage = (expression, displayElement) => { | ||
| displayElement.innerText = "invalid input"; | ||
|
|
||
| setTimeout(() => displayExpression(expression, displayElement), 500); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
I see. That's fine. Consider to show permeant text (usually appears in red). But again, that's also a solid solution 💪
| 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); | ||
| }; |
There was a problem hiding this comment.
Consider separate the handling logic.
assign the relevant function as a listener to the relevant button.
| }; | ||
|
|
||
| const validateIput = (expression, newChar) => { | ||
| const ops = "+-*/"; |
There was a problem hiding this comment.
consider to move this constant to the global scope.
The constant is created every validateIput call.
|
|
||
| const validateIput = (expression, newChar) => { | ||
| const ops = "+-*/"; | ||
| const last = expression === "\xa0" ? "" : expression.at(-1); |
There was a problem hiding this comment.
its the last char that was added to the expression . it could be an operator
add initial calculator functionality with input validation and display updates