# scope

**URL:** https://forum.kirupa.com/t/scope/637232
**Category:** Uncategorized
**Created:** [September 28, 2017, 1:02pm UTC](https://forum.kirupa.com/t/scope/637232 "2017-09-28T13:02:11Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![alphons3k](https://avatars.discourse-cdn.com/v4/letter/a/47e85d/32.png) [@alphons3k](https://forum.kirupa.com/u/alphons3k)
#### Post date: [September 28, 2017, 1:02pm UTC](https://forum.kirupa.com/t/scope/637232/1 "2017-09-28T13:02:12Z")

</div>

am a new to this world, i hope you understand.

am working on a code where the user inputs some numbers, i put them in an array, am having trouble accessing that array.  
EG

function getnum(){  
var num=[];  
num.push(prompt(enter 3 numbers));  
document.write (num); // this prints out.  
};

document.write (num);// i cannot access this array

---

<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 28, 2017, 9:27pm UTC](https://forum.kirupa.com/t/scope/637232/3 "2017-09-28T21:27:31Z")

</div>

You need to move the num array outside of the function as follows:

```
var num;

function getnum(){
   num = [];
   num.push(prompt(enter 3 numbers));
   document.write (num); // this prints out.
};

document.write (num); // now it works!
```

---

<div class="post-metadata">

### Author: ![linusj](https://avatars.discourse-cdn.com/v4/letter/l/b2d939/32.png) [@linusj](https://forum.kirupa.com/u/linusj)
#### Post date: [September 28, 2017, 9:28pm UTC](https://forum.kirupa.com/t/scope/637232/4 "2017-09-28T21:28:18Z")

</div>

ahh, man I am so slow 🙂 Kirupa beat me to it…

I guess num is declared inside the function **getnum** and not accessible for **document**?

```
var num=[]; //move here    

function getnum(){
    num.push(prompt(enter 3 numbers));
    document.write (num); // this prints out.
    };

  document.write (num);// i cannot access this array
```
