JavaScript Random Vids

Posted: 9 February 2019 by Robbie

If you see on the sidebar, I have another widget that shows a random 3-hour mix of ambient music. It’s not a real widget, just more like custom HTML with some JavaScript in it. Another thing is, I wrote a nice little article about it on this site here, but WordPress will not publish it. I keep trying to save it, I get a failure notice. I try to publish it, WordPress says publishing failed. I also tried to put separate pieces into the said article, and no dice.

So far as I’m typing this article, WordPress is saving the draft, so sans the code, I’ll show you what I’ve done. Qwick previously was a Slideshow site that was non-WordPress. It was made with PHP and BootStrap. Qwick’s previous site looked similar to a WordPress site but really wasn’t. On the sidebar, I made some JavaScript code to make a random link appear in the form of a BootStrap Card. Here’s what it looked like on the previous site:

JavaScript random card
The card on the right.

So, I took the code and began to modify it. I took the BootStrap code out of it and with four videos from YouTube, I added the embed code. I also reduced the size to 352×198 so it would fit within the sidebar of this site. I did run into problems, like not putting in semicolons. That’s something I completely forgot about with JavaScript after running away from it months ago, I’m a dummy. With the help of JSHint, I got it to work. Here is a link to the code.

Future Changes

Of course, I can improve on this JavaScript code. One idea is that I can change only the YouTube src while keeping the rest of the code intact. That is another challenge I going to tackle down the road. I’ll let you know when I succeed in it (or if).