Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
5
rated 0 times [  8] [ 3]  / answers: 1 / hits: 27361  / 12 Years ago, sat, may 5, 2012, 12:00:00

i'm creating a game in javascript for college and i have a button to call a function but i need it to include variables from another function



if i put the function inside the other function where the variables are the button doesn't call it



is there a way of doing this or to get the variables that were created in the first function and use them in the second function



it is a simple maths game where you get a random number a random sum and another random number
(i.e. 5+7, 4*3, 2/6, etc,)



so i've got a function to show the random number using



var ranNum1a=Math.floor(Math.random()*10);


i need the other function to check the users answer but i need to know what the random number was from the other function


More From » function

 Answers
14

You would need to make those variables global
example:



var myValue;
function setValue()
{
myValue = test;
}

function getValue()
{
alert(window.myValue); // yup, it's test
}


source..


[#85773] Friday, May 4, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kaitlynd

Total Points: 470
Total Questions: 108
Total Answers: 120

Location: Faroe Islands
Member since Thu, Apr 8, 2021
3 Years ago
;