Skip to content

SuperJoshua/fcc-java-calc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build a JavaScript Calculator

--> See it live.

A clunky calculator with a strictly left-to-right order of operations. And a bug that I didn't noticed until years after the FCC tests approved it: try hitting the first number twice consecutively.

This was a project required for getting the Front End Development Libraries Certificate from freeCodeCamp. It had to fulfill these "user stories".

  • My calculator should contain a clickable element containing an = (equal sign) with a corresponding id="equals".
  • My calculator should contain 10 clickable elements containing one number each from 0-9, with the following corresponding IDs: id="zero", id="one", id="two", id="three", id="four", id="five", id="six", id="seven", id="eight", and id="nine".
  • My calculator should contain 4 clickable elements each containing one of the 4 primary mathematical operators with the following corresponding IDs: id="add", id="subtract", id="multiply", id="divide".
  • My calculator should contain a clickable element containing a . (decimal point) symbol with a corresponding id="decimal".
  • My calculator should contain a clickable element with an id="clear".
  • My calculator should contain an element to display values with a corresponding id="display".
  • At any time, pressing the clear button clears the input and output values, and returns the calculator to its initialized state; 0 should be shown in the element with the id of display.
  • As I input numbers, I should be able to see my input in the element with the id of display.
  • In any order, I should be able to add, subtract, multiply and divide a chain of numbers of any length, and when I hit =, the correct result should be shown in the element with the id of display.
  • When inputting numbers, my calculator should not allow a number to begin with multiple zeros.
  • When the decimal element is clicked, a . should append to the currently displayed value; two . in one number should not be accepted.
  • I should be able to perform any operation (+, -, *, /) on numbers containing decimal points.
  • If 2 or more operators are entered consecutively, the operation performed should be the last operator entered (excluding the negative (-) sign). For example, if 5 + * 7 = is entered, the result should be 35 (i.e. 5 * 7); if 5 * - 5 = is entered, the result should be -25 (i.e. 5 * (-5)).
  • Pressing an operator immediately following = should start a new calculation that operates on the result of the previous evaluation.
  • My calculator should have several decimal places of precision when it comes to rounding (note that there is no exact standard, but you should be able to handle calculations like 2 / 7 with reasonable precision to at least 4 decimal places).

About

FCC Front End Development Libraries certification project -- this one is a poor calculator

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published