I am have trouble accessing the random index that is being chosen through randomTest. When I call randomTest in analytics_test(), I receive an undefined error. I feel as if I am not actually accessing this variable. Any tips or ideas to fix this problem? I would appreciate it, thank you!
//This function creates a loop for 5 random numbers. Each index in the array is given a variable
function createTest_Var() {
var testNumber = [];
var i;
for (i = 0; i < 5; i++) {
testNumber[i] = (Math.random() * 10);
}
var randomTest = testNumber[Math.floor(Math.random() * testNumber[i].length)];
return testNumber;
}
//This function takes chooses a random index from the array and compares it to the random number "y".
function analytics_test() {
var y = (Math.random() * 10);
var i = createTest_Var.randomTest;
if (y < i) {
//Just a test console.log ("the random numbers are: " + (Math.random() * 10));
console.log ("It is greater! " + i + "<" + y);
}
else {
console.log("not big enough " + i + ">" + y);
}
}
var i = createTest_Var.randomTest;--- what does this statement do? And why do you have 2 returns increateTest_Var?varstatement after areturnbasically does nothing. It certainly doesn't add a property to a function that you can access outside of the function.randomTestis assigned after a return statement? Can you provide a code sample on JSFiddle\JSBin?