The .length and values of the array however are randomly assigned. More specifically, a() randomly assigns anArray.length to a random value 1-3, and the values therein are also randomly assigned a value 1-3. I've coded numTester() to test for 2 within anArray after a() is executed.
var anArray = [];
var numTester = function(aryParam, v) {
var i;
for (i = 0; i < aryParam.length; i++) {
if (aryParam[i] == v) {
return true;
}
return false;
}
};
var a = function() {
b = 0;
c = setInterval(function() {
b++;
d = Math.floor(Math.random() * 3) + 1;
anArray.push(d);
if (b == d || b == 3) {
clearInterval(c);
document.write(anArray.join(", "), "<br />", numTester(anArray, 2));
}
}, 1);
};
a();
numTester() is supposed to return true if 2 is any of 1, 2, or 3 numbers within the array. The issue is that I've found that it will only return true if the first number of the array is 2. Why is this?
var anArray = [];
var numTester = function(aryParam, v) {
var i;
for(i = 0; i < aryParam.length; i++) {
if(aryParam[i] == v) {
return true;
}
return false;
}
};
var a = function() {
b = 0;
c = setInterval(function() {
b++;
d = Math.floor(Math.random() * 3) + 1;
anArray.push(d);
if(b == d || b == 3) {
clearInterval(c);
document.write(anArray.join(", ") + "<br />", numTester(anArray, 2));
}
}, 1);
};
a();
anArray.some(x => x == v). ;-)