This is the full app version of Calc You Later Backend, with front end and everything. The logic's there, we just need an interface!
The entire back end has been completed for you. You'll be working entirely in main.js
.
Note: we are not asking you to handle multi-word operation names like "divided by" until stretch goals. So don't worry about them yet! Here are the basic steps you'll need to follow.
- The first thing we need to do is
require
ourcalculate
function in fromcalculate-back-end.js
. If you've forgotten the syntax, check your previous assignments. (Or your friendly local search engine.) - Then we'll need to grab our users' input. IMPORTANT: we want this app to be user friendly, so we'll ask our user to give us the input in a more human way. That means we'll ask them to write
node main.js 3 + 3
, NOTnode main.js 3 3 +
, which is the computer-y order ourcalculate
function asks for. Be sure to save yourgetInput
results in the right variables, knowing what order they'll come in as! - Now that we have the input, pass it to
calculate
. - Now assign the return value from
calculate
to a variable and print it!
And that's it! That's our whole front end!
- The main stretch goal is to allow them to use multi-word operations like "divided by" or "multiplied by" and such. What we'll need to do to make that happen is to check whether a fourth node argument was entered. If they entered
node main.js 3 + 3
, thengetInput(3)
would beundefined
. If they enterednode main.js 3 added to 3
, thengetInput(3)
would be3
, as there would be one more argument in the middle, pushing the second number back one index.
So how do we handle this? There will be two issues: branching our logic (if there are 4 arguments, run different arguments through calculate
, otherwise, run the code the way we already did it), and combining our operation into one string ('added to' versus 'added' and 'to').
- This is a very advanced stretch goal, most likely requiring a loop or the string method
slice
, and plenty of research: allow the user to write as many words as they want before the first number. So not justnode main.js 3 times 3
, butnode main.js what is 3 times 3
or evennode main.js can you please tell me kind sir what is 3 times 3
. Plenty of work there. Good luck!