Blog

22 de June de 2023

Using Random

Usando Random

If you've ever browsed a website and noticed a randomly changing element, like an image or a callout, you might be wondering how this is done. One way to create this functionality is by using randomization functions in JavaScript.

In JavaScript, you can use the “Math.random()” function to generate a random number between an informed limit number. For example, the following code returns a random number from 0 to 5:

<script type="text/javascript">

	$num = Math.floor(Math.random() * 5);
</script>

With this we can have several applications, such as this image below that changes every time you refresh the page.

Share:
Others

Tips

Protótipo em site

Prototype on site

View more

Propriedades do Cursor

Cursor Properties

View more

ShadowBox

ShadowBox

View more