# Problem with JS variable scope?

**URL:** <https://forum.freecodecamp.org/t/problem-with-js-variable-scope/128318>\
**Category:** General\
**Created:** [June 17, 2017, 2:43am UTC](https://forum.freecodecamp.org/t/problem-with-js-variable-scope/128318 "2017-06-17T02:43:04Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![stephanpssantos](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/stephanpssantos/32/71766_2.png) [@stephanpssantos](https://forum.freecodecamp.org/u/stephanpssantos)\
**Post date:** [June 17, 2017, 4:03am UTC](https://forum.freecodecamp.org/t/problem-with-js-variable-scope/128318/2 "2017-06-17T04:03:28Z")

</div>

Hi there. I’m still learning myself, so I can’t give you an explanation on why that won’t work, but maybe I can help get you there.

```
window.onload = tester();
var test;

function tester() {
	$.getJSON("http://quotes.stormconsultancy.co.uk/random.json", function(json) { 
		processJSON(json); 
	});	
}

function processJSON(json) {
	test = json.quote;
	alert(test);
}

```

That worked for me, so I suspect that this is an issue more with $.getJSON than with scope.

Hope it helps.

---

_[View the full topic](https://forum.freecodecamp.org/t/problem-with-js-variable-scope/128318)._
