slickCall = {
slidesToShow: 1,
accessibility: true,
dots: true,
arrows: true,
autoplay: _.autoplay,
pauseOnHover: false,
adaptiveHeight: true,
initialSlide: _.randomize ? randomizeSlideshow() : 1 // undefined if _.randomize = true
};
setTimeout(function() {
console.log(slickCall);//shits still returning undefined
},4000);
function randomizeSlideshow() {
console.log("this got to run");
var math;
$.getJSON(_.url).done(function (data) {
math = parseInt(Math.ceil(Math.random() * data.objects.length));
console.log(math + " :first"); // 1-8 depending...all good here
return math;
});
console.log(math + " :final"); // undefined
};
I’m trying to get the initialSlide setting to get a random value. In this instance, _.randomize is true, and is supposed to return a value from 1-8 (data.objects.length). It’s always undefined though. What can I do?
This isn’t how you do things asynchronously. You’re always going to get undefined, because you’re never going back and updating the original object. The object declaration isn’t going to hang around waiting for initialSlide to be defined.