# Creating a Function that Returns Data

**URL:** <https://forum.kirupa.com/t/creating-a-function-that-returns-data/661548>\
**Category:** programming\
**Created:** [September 12, 2023, 7:03am UTC](https://forum.kirupa.com/t/creating-a-function-that-returns-data/661548 "2023-09-12T07:03:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anand\_Singh1](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/anand_singh1/32/23466_2.png) [@Anand\_Singh1](https://forum.kirupa.com/u/Anand_Singh1)\
**Post date:** [September 12, 2023, 7:03am UTC](https://forum.kirupa.com/t/creating-a-function-that-returns-data/661548/1 "2023-09-12T07:03:31Z")

</div>

Hello Kirupa,

I am referring your book on Absolute Beginner’s Guide to JavaScript  
Chapter 3 - Functions  
I’m doing exactly the same as per instructions given in the book but I am not getting any result when I go live on visual studio code. there is no dialog box.  
Please help me.  
Here is my code from VS

```auto
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Get Distance</title>
  <style>

  </style>
</head>
<body>
  <script>
    
    function getDistance(speed, time) {
      let distance = speed * time;
      return distance;
    }
    let myDistance = getDistance(10, 5);
    
  </script>
</body>
</html>

```

---

<div class="post-metadata">

**Author:** ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)\
**Post date:** [September 12, 2023, 6:26pm UTC](https://forum.kirupa.com/t/creating-a-function-that-returns-data/661548/2 "2023-09-12T18:26:07Z")

</div>

Hi @Anand_Singh1 - in the way I described the code, I was unclear in my expectation. That’s a bug on my end.

The `myDistance` variable correctly stores the returned value from the `getDistance` function. To display the result, add an `alert(myDistance)` at the end:

```js
let myDistance = getDistance(10, 5);
alert(myDistance); // <-- new line to add

```

Hopefully this helps! I’ll revise this section in a future edition 🙂

Cheers,  
Kirupa

---

<div class="post-metadata">

**Author:** ![Anand\_Singh1](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/anand_singh1/32/23466_2.png) [@Anand\_Singh1](https://forum.kirupa.com/u/Anand_Singh1)\
**Post date:** [September 13, 2023, 6:19am UTC](https://forum.kirupa.com/t/creating-a-function-that-returns-data/661548/3 "2023-09-13T06:19:00Z")

</div>

Thank you so much Kirupa!! You’re the best!!

---

<div class="post-metadata">

**Author:** ![naimehossain37](https://avatars.discourse-cdn.com/v4/letter/n/aeb1de/32.png) [@naimehossain37](https://forum.kirupa.com/u/naimehossain37)\
**Post date:** [September 13, 2023, 6:28pm UTC](https://forum.kirupa.com/t/creating-a-function-that-returns-data/661548/5 "2023-09-13T18:28:09Z")

</div>

This a really great post
