Skip to content

The current example calculator does not allow for chaining of operations. #6130

Open
dwhitebud opened this Issue · 8 comments

7 participants

@dwhitebud

The current example calculator, while extremely well done from a front end perspective, does not allow for chaining of operations. Since this is now a requirement, the example should be capable of doing this.

It also has some quirks with decimal points that might want to be addressed (allows for multiple decimal points, places the decimal point at the second position until another digit has been entered)

@SaintPeter
Free Code Camp member

@storbeck - Is this something you want to look into?

@dwhitebud

I should clarify, it does chain operations, but only if you press equals. It does not update the value along the way like a calculator does. My mistake if this is the desired functionality.

@simondiep

@dwhitebud If you are referring to http://www.freecodecamp.com/challenges/build-a-javascript-calculator : I've noticed the user stories, site, and demo video are all slightly different. The chaining user story is a bit vague, which could have been intentional. However, since the demo video and the current live example on Codepen implement the solution in different ways, this could be confusing for new developers.

I'd suggest either updating the user story to be more clear on what chaining means, or to update the demo video to use the new Codepen example.

@bugron

@dwhitebud @SaintPeter @storbeck any updates on this issue?

@bugron bugron added the blocked label
@storbeck

I don't have time to work on this, the example is forked off of mine to the FreeCodeCamp codepen account so the issue isn't blocked. It is working as it was originally designed, this is a new feature request.

@bugron

@storbeck OK. In that case we need to replace the example project with one that satisfies all user stories.

@bugron bugron added help wanted confirmed and removed blocked labels
@StevePaytosh

If anyone is curious how to implement chaining, one way to do this would be using reverse polish notation (or post fix notation). It utilizes a stack to order all the operators at the end of the expression, so a (theoretically) infinite number of operations can be executed in the proper order.

@asantos00

The basic calculators normally "simulate" a click in the "=" when you enter the second operator, they do not worry about the polish notation, only by the order of the numbers and operators.

Something like 4 + 5 * (calculator automatically does 4 + 5) and then it does the multiplication.
Maybe that's a simpler solution than implementing the solution with the chaining using the polish notation refered by @StevePaytosh .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.