Q:

Accessing a variable obtained by user from separate file in JS

A beginner question:
I'd like to create an app where I obtain an imaginary number from user and plot it to complex plane. Since I'm hoping to add other things later, I keep the code in separate files, connected in HTML file.
In first file, I get the real and the complex part from the user:
$(document).ready(function() {
$("#button-number").click(function() {
    var realPart = prompt("Please, enter the real Part of the number:")
    var imagPart = prompt("Please, enter the imaginary Part of the number:")
});})

which I use in the second file:
$(document).ready(function() {
var c = document.getElementById("ComplexPlane");
var number = c.getContext("2d");
number.beginPath();
number.arc(500+50*realPart,300-50*imagPart,10,0,2*Math.PI);
number.stroke();
number.fill();})

However, this doesn't work. It works if I define the variables manually outside the function. I'm not entirely sure how are all the operations timed, since my variables aren't defined when the document loads. I'd love to know how to solve this issue. 

A:

This works as expected. 
Instead using global variable scope you could use localStorage
http://www.w3schools.com/html/html5_webstorage.asp
you can store the real an imaginary part numbers in localStorage in your first file. And you can access them in your second file.

