i am working on React Calculator Apps, i have seen many coders using “waitingForOperand” for a state but i couldn’t find any material explain further about it?
it seems many function and state is unknown for me as beginner, i found it difficult to understand when i trying to do the projects.
i am watching tutorials and dropped notes during projects, am i going a right path?
or should i try to build everything by myself first?
Thanks in advance.
That is very specific, so I assume in that particular piece of code (and if you have seen it many times then you are looking at code that has been copied) is there to indicate the app is waiting for for a user to enter an operand (
=). EDIT: god I’m half asleep here, those are operators, operand is the number as @chuckadams says
It isn’t possible to fully explain how the logic works because I can’t see the code.
But I assume that if a user has not entered some numbers yet, and the calculator shouldn’t do anything until they enter an operand, so that property will be
true. And if they enter an operand, the calculator should calculate, and the property will be
If I understand correctly,
waitingForOperand is a state you would set in a calculator application as someone has pressed an operator and it is waiting for an operand (a number to apply the operator).
In a basic calculator the operators will be
+, -, *, /, =
for addition, subtraction, multiplication, division, equals
As long as the user is typing in a number the state of the calculator app will be
waitingForOperator so that once the user presses one of the
operator symbols your calculator can assume that the user has finished entering their number/operand and they want to perform the selected operator on a new number/operand.
So once an operator has been selected, the state of the app would change to something like
waitingForOperand and should not accept any other inputs except for an operator
+, -, *, /, = or
Then once a operator has been entered the state of the application would then return back to
waitingForOperand unless the operator selected was the
= in which case it should calculate the answer.
Also these states and functions are likely not part of the JS language or the framework/library you are using. They are states and functions that are thought of and coded by the person building the application.
So there isn’t any documentation or guides on how to use these states and functions
Stuff you can read about and learn is the JS in-built functions like Math
+ - * / are operators, not operands. The waitingForOperand state should come when someone has hit an operator key and the next number will be acted on by the previous operator. It’s possible though that the terminology confusion is in the original code itself – I haven’t read it.
Oh this is true, we got mixed up.
The numbers are operands and the operators are the symbols