Project Overview: I have a basic calculator app built using Node.js that performs addition, subtraction, multiplication, and division. However, there's a bug that causes the app to crash under certain conditions. I need help identifying and fixing the issue.
Calculator Functionality: The calculator app accepts two numbers and an operator as inputs via a simple command-line interface (CLI). It performs the requested operation and outputs the result. Here is the structure of the app:
Current Bug: When the user inputs invalid data (e.g., a non-numeric value for one or both numbers), the app crashes with a NaN result or a confusing error message. The app does not properly handle invalid user input.
Expected Behavior:
If the user enters a non-numeric value for either num1 or num2, the program should display an appropriate error message (e.g., "Invalid input, please enter a number") and gracefully exit.The app should continue to perform the calculation correctly when valid inputs are provided.
As you can see, when the user inputs a non-numeric value like "ten," the app does not catch the invalid input and instead returns NaN. The user is not notified that they made an error, and the app does not handle this gracefully.
Scope of Work:- Validate the user's input to ensure both numbers are numeric.- Display a clear error message if invalid input is detected.- Ensure the app handles edge cases such as entering nothing, large numbers, or invalid operators.- Improve error handling to prevent the app from crashing unexpectedly.
Let me know if you have experience with input validation and error handling in Node.js. Thank you!
该外包需求信息来源于站外平台,本站仅提供公开信息部分字段展示与订阅服务,更多请查看免责声明。