Giter VIP home page Giter VIP logo

react-advanced-calc's Introduction

Advanced React Calculator

Remember the calculator we made during the in-class lab? Well, let's take it to the next level!

Let's try building an app like the one that comes default on your Mac.

Mac Calc App

Prerequisites

You will need to know the following concepts before attempting this challenge:

  • ES6 Arrow Functions
  • React events (such as onClick)
  • React State

Steps and Set Up

  • Fork and Clone this repository
  • Run npm install to install dependencies
  • Run npm start to see your basic create-react-app boilerplate
  • Implement the requirements below AND one of the bonuses (or more if you have time!)
  • Push the code back up to your fork
  • Make a pull request against the base fork
  • 🎉 Celebrate 🎉

Requirements and Planning Process

You will need to implement the following:

  • AC (Clear) button (clear the state)
  • 4 main operators + - / * (store operator in state)
  • 0-9 buttons (store numerical value in state)
  • Equals button (evaluate the answer based on your current state)
  • Error messages if the user makes a mistake (such as trying to use two operators)
  • A display that shows the current number or current state
    • You can implement it to match the Mac built-in behavior showing the current value only no operator
    • Alternatively you can show the whole equation if you'd like (as on a graphing calculator)
  • Basic styling to match the Mac built-in app
    • Orange operator buttons
    • Dark gray display
    • Light gray number buttons

Avoid some potential pitfalls

  • Ensure you can use numbers with multiple digits (e.g., can you add 10 + 20?)
    • Make sure you are concatenating each number pressed until you get an operator
  • Don't accept 0 as a first number (e.g., 002 should not be allowed)
    • Possible exception - if you implement floating point numbers as part of the bonus, you may have a 0 preceeding the decimal point. Still, while 0.1 is valid, 0000.1 is not, so be sure to only add the 0 in front if the . is pressed first!

Bonus

Choose any of the following:

  • Alter your app's logic for the - operator to allow negative numbers to be input
  • Implement the +/- button that switches a number from negative to positive or vice versa
  • Implement the % button either...
    • As a true modulus operator
    • As a percent button, like it is on the Mac program (just divides current number by 100)
  • Implement the floating point . button in order to support decimals.
    • Don't allow more than one decimal per number!

react-advanced-calc's People

Contributors

amishizaki avatar brandiw avatar taylordarneille avatar 009kings 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.