Code Challenge - jQuery Simple Calculator
Students will work in groups to create a simple calculator using jQuery event listeners and JavaScript if/else or switch statements.
Steps
- Fork this repository.
- CLone Your fork.
- cd into the folder for this project.
- open index.html in the browser and bring up the JavaScript console.
- open the project folder in your code editor.
- In js/simple-calc.js write the code neccesary to make a functioning calculator.
The calculator should do the following:
- the calculator should store 2 separate numbers as variables.
- the calculator should store the operation the user chooses as a variable holding a string: '+', '-', '*', '/'.
- when a user clicks increment or decrement buttons it should add one or subtract one from a variable storing that number and update the h2 with a class="number" showing the updated number.
- When the user clicks the operation buttons it should change the string that is being stored in the operation variable.
- When the user clicks the equals button, the calculator should update a result variable based on the operation choosen and the value of the two numbers. It should then report the result into the h2 with an id="result".
See a live working example of the simple calculator here
Resources
- MDN - Vars
- MDN - Switch Statement
- MDN - if/Else Statement
- jQuery API - Selectors
- jQuery API - Events - Click
- jQuery API - Text
- Live Working Example
View Code Challenge - jQuery Simple Calculator on Learn.co and start learning to code for free.