Question: In this assignment, you will create a Node.js script that converts pounds to kilograms. The script will take one command line argument, which is the

In this assignment, you will create a Node.js script that converts pounds to kilograms. The script will take one command line argument, which is the weight in pounds, and print the converted weight in kilograms to the console.
1. Create a new JavaScript file named weight-converter.js.
2. In this file, write a script that converts pounds to kilograms.
3. The script should take one command line argument, which is the weight in pounds.
4. The script should print the covered weight in kilograms to the console. The output should be rounded to two decimal places.
5. If the script is run without a command line argument, it should print the following message: stderr: Usage: node weight-converter.js
6. If the script is run with a non-numeric command line argument, it should print Input must be a number. to stderr.
How to Run the Script To run the script, use the following command in your terminal:
node weight-converter Replace with the weight you want to convert. 24 How to Test the Script To test the script, use the tester.js file provided with the assignment. Run the tester with the following command:
node tester.js Hints:
Use process.argv to access the command line arguments.
Use console.error to print error messages to stderr
Use process.exit(1) to exit the script with a non-zero status code when an error occurs.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!