How to implement a random link with Javascript

In this article we will see how to make a link that takes us to any URL. The address of the link will be selected randomly, among the elements of an array.

This is one of the first Javascript workshops that we wrote, with an effect that was quite typical in web pages before, creating a link that will randomly direct you to any page, among various alternatives that we can define.

For this we will use the Javascript language that will be executed in the browser. It’s going to be extremely simple, so it’s a good workshop for beginners and we think it will be instructive for readers.

Create the link array

To begin with, we are going to create an array with the different sites where our link could lead us. We have to define this array, logically, within a

In this way we have achieved two improvements:

Loading Facebook Comments ...
Loading Disqus Comments ...