Giter Site home page Giter Site logo

calculator-app's Introduction

Getting Started with Create React App

This project was bootstrapped with Create React App.

React: Calculator Calculators are always handy to have in the browser! In this challenge, you'll make a simple calculator application. While the capabilities will be limited, the calculator will only respond to valid mathematical expressions.

Buttons on the calculator The calculator will feature a traditional, button-based interface and with no bells or whistles (no parenthesis, decimals, or special functions). There will be 16 buttons on the calculator:

A set of numerical buttons permitting entry of digits 0-9. A set of four operation buttons corresponding to addition +, subtraction -, multiplication * and floor integer division /. An equals = button, which evaluates the expression shown on the display. A clear c button, which resets the calculator to a blank state. Rendering your calculator Layout, CSS and use of child components is up to you. The deliverables which the testing suite requires are specific classes which should be attached to buttons and the output element. Here is the comprehensive list of these elements and classes which the Calculator component must render for the testing suite to function:

contains a depiction of the current state of the calculator. It can only render characters corresponding those available on the below buttons. , ... (one for each digit from 0-9) enable the user to enter numbers. , , and enable the user to enter a mathematical operator (addition, subtraction, multiplication and division, respectively). enables the user to compute the result of an expression. enables the user to reset the state of the calculator. Permitted operations The operation of the calculator must adhere to a set of specifications described in this section.

The display portion of the calculator should respond to button presses according to the following rules:

The display starts out showing the empty string. This is the state which the calculator returns to upon the user clicking clear or a computation attempting division by zero. When the display is empty, the only buttons that will work are the digit buttons and the - subtraction button (which acts as a negative sign in this context). Any other button will have no effect. When the last entered data is a digit, any button will work. If a digit is the last data entered and another digit is pressed, the new digit will be appended to the display. If a digit is the last data entered and an operator button is pressed, the operator will be appended to the display. Pressing = should only compute the result of the expression if the last entered character is a digit. When the last entered character is an operator, it's permissible to follow it with any button except =. New digits should be appended and new operators will be handled as follows: If the trailing operator is + or -, all operator presses will replace the old trailing operator with the new operator. For example, if the display shows 5- and the / button was pressed, the display should show 5/. If the trailing operator is * or /, all operator presses will replace the old trailing operator with the new operator with the exception of -, which will be appended to the display, making it possible to create legal display states such as 6/-. Once the display enters a state with two consecutive operators such as 6/-, any further operator presses can be ignored entirely until a digit is pressed. No leading zeroes are allowed in any circumstance (the single digit 0 is not considered to have leading zeroes, but 00 or 08 are illegal numbers). When a button is pushed that would create a leading zero, replace the zero with the new number. For example, if the display shows 5+0 and 8 is pressed, the display should show 5+8. If any number is divided by zero, the calculator should reset to the blank origin state as if c had been pressed. If a computation has been performed (i.e. the = button has just been pushed and the display contains a single number), clicking an operator button will extend the result as the first operand of a new expression, but pressing a digit will begin a new expression as if the display state had been clear. Illegal display states include:

  • or +67+8 (leading operator other than -) --3, 5+-3, 5-+3, 5/+6 or 67*/8 (two consecutive operators that don't include either a * or / followed by -). 706 or 067 (leading zero) Legal display states include (with results after pressing =):

-8-9 => -17 -8-9*-6 => 46 (order of operations is respected) -0*-0 => 0 0*-0 => 0 6/0 => (reset to empty string origin state due to division by zero) 6/-0 => (reset to empty string origin state due to division by zero) Here are examples of legal states, but are incomplete expressions, so pressing = has no effect:

-5 5* 5- Additional notes Since the calculator uses floor division for all operations (intermediate operations included) and does not accept decimals as input, results will differ from division on a normal calculator or as produced by eval. You must implement your own miniature expression parser for full credit in this challenge.

You may assume only small numbers are input; there's no need to worry about integer over- or under-flow in input, output or at any stage of the computation.

Comprehensive tests will be provided to you. Feel free to make changes to the test suite as you see fit--these changes will be ignored for the final submission.

CSS and UX are important, but secondary to logical functionality. Although there is no predetermined single solution or set of requirements for style, please take some time to present an interface that shows a fundamental grasp of the domain.

Demo This demo exercises the application requirements described above.

calc.gif

Remember, style is up to you--there's no need to copy the design shown here.

calculator-app's People

Contributors

agkayster avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.