Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Node.js Basics 2017 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: https://www.amdoren.com/currency-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:

number                                                                                                                                                                                                  
valid                                                                                                                                                                                                   
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. 

snapshot: https://w.trhou.se/lwrokmg5f8

1 Answer