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

Ariana Maksimović
Ariana Maksimović
2,797 Points

Capture Input (JavaScript)

Hello,

I am starting taking courses of JavaScript Basics and I get stuck in one of courses, which is Capture Input. I am beginner at this field so I have questions:

  1. What is the point of that course?
  2. What does returning a value mean? (I would need really explanation but really basic one or easy one)

Thank you :)

2 Answers

A1) The course teaches you the basics of how you can get user input to make different things happen. In the course you will most probably use the prompt() method of getting user input. It is a very basic way of getting users to interact with your code. But gradually, as the course develops, you will use advanced methods of getting user inputs, for example, grabbing user inputs from a form field that they fill out, or what buttons they have clicked on a page and so on.

A2) A return value is often used in JavaScript functions to return a value to be used in other ways, whether it is making calculations with that returned value or displaying it on the page along with other things. When used in a function, its often the last piece of code that is in the function... Which means at a return value, the function ends. Any other piece of code you put inside your function after a return statement will not be counted and JavaScript engines will not see it once it is parsed.

For more information on that, I have provided a link here with some great explanation of what it is and the usage:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/return

Thank you for your question, I hope this has answered.

Ariana Maksimović
Ariana Maksimović
2,797 Points

I couldn't have better explanation which is yours. Thank you very much :)

I am glad this has answered your question. As a beginner all this may be daunting when you are learning, but don't worry, it just needs practice and you will do just fine.

Have a nice day :)

Ariana Maksimović
Ariana Maksimović
2,797 Points

Hello furkan

yes, now for me everything is new, especially in JS but with practice actually someday for me all this will be piece of cake. I have again other question. Now I have understand return statement but still I don't understand when Guil in video says:"In programming speaking the prompt returns a value." Okay, how it returns if it doesn't have return statement.

Thank you for answer.

That is because prompt() is a function and remember I told you before that a function can have a return statement inside to return a value.

Well, you don't necessarily see the return statement there in the prompt, but JavaScript engines will treat anything you put between the parentheses () as a return value.

Look at the following code snippet, make sure you read the comment in the code snippet aswell:

prompt("What is your name?"); 

/* This line
will return a box that appears on the screen 
which asks the question
 "What is your name", and anything you type into that box becomes a return value. */ 

I hope that has answered your question.