Skip to content
Advertisement

How do I pass user input as a string in an API request?

I am trying to take user input (zipCode) and pass that into an API request. How do I format the zipCode user input so that the GET request reads it as a string.

JavaScript

As you can see above, I have tried to declare another variable that turns the zipCode into a string.

Advertisement

Answer

Firstly, function user_input() returns which means that in the left side of function call you need to have a variable in which you pass return from function. Secondly, you need to pass this variable to a function.

The third thing is that input() outcome is a string even if you provide number.

JavaScript

Snippet based on your code

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement