Hey folks!
I am new to coding, I have been slowly picking away at FCC, but other than that, total noob. I’m working on building a calculator for the Front End Development Libraries Projects.
I’ve taken a few wacks at it and I have had trouble with multiplying decimals.
additionally I can’t seem to find the issue in why my input won’t show up in the display now. If you see something else, let me know.
You’ve got some syntax errors which are preventing your JS from running propery. You can use codepen’s JS analyzer to help you find them. I’ll get you started:
My problem is when computing 5 + * 7 = 12 . it should solve to 35.
I should be able to click multiple operators and it only use the last operator pressed.
This is my code so far for the Operator buttons. I’m not sure where I’m going wrong.
Sorry, I’m still only getting 7/16 passed in your codepen and numerous JS errors in the console, so I can’t even test that formula in your calculator. Did you perhaps start a new one and have a different URL?
Also, you have a typo on line 142. I think you left out the first n in patternForNumbers.
As for 13, the formula the test is using is 5 * - + 5. Where in your code are you handling the case where the user inputs a multiplication sign, then a minus sign, and then a plus sign?
I have been trying to work it in at line 30, in chooseOperation(operartion). If there are multiple operations chosen, use the last operator.
I have also tried at line 121; It is currently a note. To replace operation when there is already an operator.
In the chooseOperation function I would add a console log at the beginning and look at both the operation passed in and the value of this.currentOper. And then try 5 * - + 5. Are these values what you expected them to be?
Also, what are the possible values of this.currentOper? Because you have
if (
this.currentOper === "/[+*/]/" &&
this.currentOper.includes("/[+*/]/")
) {
Is the string /[+*/]/ really a potential value of this.currentOper?
After the first operation is clicked, it shows in the console. When I click more operationButtons, they show an empty string in the console.
I have tried various if statements, replace(), slice() and various potential values of this.currentOper in operationButtons , updateDisplay, and chooseOperation.
I know I need it to change the operator when I click operationButtons and before it gets to the this.compute step in chooseOperation. I just am not sure how to go about that.
I have tried to add an addEventListener('change' , ()=> to update the operation each time an operationButton is clicked, but it still won’t update the first clicked operation.