0

I have to admit I am quite the newbie when it comes to JavaScript. Spent the last few years working on hardware and haven't been able to keep up.

Anyways, I am trying to use Tubular ( http://www.seanmccambridge.com/tubular/ ) except I am trying to pick from an array of video ID's instead of just the one. For example, refreshing the page loads a different video ID and by relation, loads a different video.

This is the actual function:

$().ready(function() {
$('body').tubular('ID-GOES-HERE','wrapper'); 

I have tried doing this on my own but in the end I simply managed to break it entirely. Any suggestions are welcome!

asked Aug 15, 2012 at 5:18
0

3 Answers 3

2

Something like...

var myIDs = [1,2,3,4,5,6,7,8,9,0];
var selectedID = myIDs[Math.floor(Math.random() * myIDs.length)];

This will give you a randomly selected item from the array

answered Aug 15, 2012 at 5:21
Sign up to request clarification or add additional context in comments.

Comments

0
var videoIDs = [1,2,3,4,5,6];
var randomID = videoIDs[Math.floor(Math.random() * videoIDs.length)];
$(document).ready(function() {
 $('body').tubular(randomID,'wrapper'); 
});
answered Aug 15, 2012 at 5:24

Comments

0

If you wanted to get between 1 and 6, you would put

Math.floor(Math.random() * 6) + 1

You can replace 1 and 6 with how much videos you have in that array or use array.length function if you want it to be dynamic.

Try that and see if it works for you.

answered Aug 15, 2012 at 5:25

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.