In this task, you'll create a calculator that has two numbers and an operation, and the calculator will perform the operation on those two numbers.
You'll create an integer variable that contains the first number, another integer variable that contains the second number, and a third string variable that contains the operation.
Example, the two numbers could be 3
and 5
, and the operation could be "+"
, then the calculator will add 3
and 5
, and print to the console 3 + 5 = 8
.
This is an example of what your terminal should look like:
```
Please enter the first number: 5
Please enter the second number: 7
Please choose the operation (+, -, /, *): *
---------------
5 * 7 = 35
```
In your terminal, make sure you're inside the task directory and run npm install
.
- In
calculator.js
, ask the user for two numbers and operation using theprompt
method we provided. - Validate user input.
- If the user's inputs were not numbers, print to the user that the numbers were invalid. For example if the user enters letters instead of numbers.
- Hint: Prompt will give you the value as a string, hmmm what should we do?
- If the operation the user entered was not any of the options (
+
,-
,*
, or/
), print to the user that the operation is not valid.
- If the user entered valid numbers and a valid operation, perform the calculation and print it to the user.
To submit your work, simply push your code to GitHub.
After finishing the task and verifying your work, follow these steps to push your code to GitHub:
- Navigate to project root (where
calculator.js
is). - Run the command
git add .
- Run
git commit -m "Solved the Conditionals task"
. - Push to GitHub:
git push
.