171
rated 0 times
[
175]
[
4]
/ answers: 1 / hits: 16575
/ 7 Years ago, sat, november 18, 2017, 12:00:00
I know that this is fundamental JS, but I'd like a simple explanation. From what I've read, If i declare an empty variable outside of my loop, the variable inside the loop should be accessible globally? Or am I totally wrong?
I would like to access randAd
from outside my for
loop.
var mobileAds = [
mobile/bb.jpg,
mobile/eyeko.jpg,
mobile/farfetch.jpg,
mobile/fsb.jpg
];
var randNum = (Math.floor(Math.random() * mobileAds.length));
var randAd;
var i;
for (i = 0; i < mobileAds.length; ++i) {
randAd = (mobileAds[randNum]);
}
More From » jquery