It's time to build a calculator. You all have some idea of how a calculator works: you enter two numbers and an operator and then the calculator gives you the solution.
You'll be coding your solution in js/calc.js
. You also need to fill out index.html
. We've left it blank this time, so you'll need to fill out the basic HTML structure and link your JavaScript file. Remember to have index.html
open in the browser so that you can see the changes you made to js/calc.js
.
Think about how you take in user input with Javascript. What function did we use for that? You'll want to store the input from your user in variables so you know what numbers and operator they want to work with.
From there, you'll want your app to trigger different actions based on the information the user entered. If they entered a +
then you want the calculator to do addition, subtraction for -
, etc.
How all of this comes together is up to you!
It would be pretty cool if you could make this like a normal calculator on the computer where you just typed numbers and the operator into a form and pressed submit. You'd have to use jQuery for for submission, and some HTML to create the form. It might take some seriously Googling, but see if you can give it a try!
View JavaScript Calculator on Learn.co and start learning to code for free.