Your script must have:
- A function that adds two numbers and returns the result
- A function that multiplies two numbers and returns the result
- A function that divides two numbers and returns the result
- A function that subtracts two numbers and returns the result
- Each function will have 2 parameters,
- On the console the prompt will print to the user:
- Please enter your first number (store that number)
- Please enter your second number (store that number)
- Please enter the operation to perform: add, sub, mul, div (then store the operation)
- Based on the operation entered by the user, you will call one of your 4 functions to perform the correct operation
- You will then print to the console: The result is: [the result]
To get set up:
cdinto the folder you'll be working in.
npm install readline-sync
- At the top of your JS file, include
const readline = require("readline-sync")
- For documentation on the
readline-syncpackage, check out the readline-sync docs on npmjs.org
Spend some time making sure you know the difference between a function call's "argument" and a function's "parameter".
You will have an if statement run a different function depending on what the user chooses on the third readline prompt.
A function can take values as arguments and a function will return a value. If you console log the function call, you can see that value.