Keyword Return

Hi guys,

So I’m studying Javascript w/ the Javascript - Absolute beginner’s guide book from Kirupa, and I got stuck on the “Return Keyword” (page 35 on the 3rd edition).

So my code looks like this:

function getDistance(time, speed) {
let distance = time * speed;
return distance;
let myDistance = getDistance(10,5);

Exactly like it is on the book. But when I run this code, it does not return anything. What did I do wrong?

Thank you in advance!

Hi @Claudia_Fetter - your code looks right to me! When I test it out in the console, it also returns the correct value of 50:

If you add a console.log(myDistance); after the last line, do you see the value for myDistance being printed as 50 as well in our console?


Hi Kirupa,

Yes, using the console.log I managed to display the 50 result. But not on the Visual Studio Code! Like I couldn’t display this “50” in a HTML page, using just this code. I can only display using the “alert” function.

Thank you for your answer! Btw, do you suggest any other programs to run the javascript codes, beside the Visual Studio Code?



You can use a program like RunJS to get instant keystroke code execution…

Just be careful though… If you write a while loop you will blow the stack while writing :stuck_out_tongue_winking_eye:

1 Like

VS Code is your code editor, and it is probably one of the best ones out there for web development. To test your app, you’ll need to use the browser and bring up the developer tools to display any console.log messages.

You’ll soon be adding code that will display values directly to the web page. The sections on the DOM will cover all of that, so using console.log is going to be a temporary pain point :slight_smile:

Alternatively, you can use a coding playground like Codepen:

I generally am not a fan of coding playgrounds for it doesn’t scale to how you will be writing your web apps for many real-world scenarios.

Oh I see!! I got it now!! It’s inside of the console on my html page.
Thank you!

1 Like