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.
Create a new JavaScript file named weightconverter.js
In this file, write a script that converts pounds to kilograms.
The script should take one command line argument, which is the weight in pounds.
The script should print the covered weight in kilograms to the console. The output should be rounded to two decimal places.
If the script is run without a command line argument, it should print the following message: stderr: Usage: node weightconverter.js
If the script is run with a nonnumeric 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 weightconverter Replace with the weight you want to convert. 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 to exit the script with a nonzero status code when an error occurs.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
