JavaScript Node.js Basics Create a Command Line Weather Application Handling Errors - Solution

how to turn an argument from the command line to a numeric value

I have done the challnage Andrew mentioned which is building a coins converter command application but i got a problem.

Im using this api:

The project is working 100% without the command line argument and i tested it by using an hard coded argument that pass in into the api.

working exmaple:

Status code: 200                                                                                                                                                                                        
{ error: 0, error_message: '-', amount: 18.2364 }                                                                                                                                                       
The converted currencey from USD to EUR for the amount of 20 is 18.2364EUR 

i run the app like this: node <path> USD EUR 2(which functions has my arguments at the convertCoin function at the app.js file. when i try to implment the option for users to pass in 2 currencies and an amount to convert, i see this error:,

{ error: 300,                                                                                                                                                                                           
  error_message: 'Amount must be numeric: undefined.',                                                                                                                                                  
  amount: 0 }                                                                                                                                                                                           
There is an error from the API : Amount must be numeric: undefined. 


1 Answer