Category: Vanilla Javascript

Added: 22nd of October 2018

Viewed: 1680 times

Generate a random number between 1 and 5 using Math.floor and Math.random commands in Javascript

The code below generates a random number between 1 and 5

Create a new .html document on your desktop, and rename the file example3.html
Open the document in your text editor and copy and paste the following code.

<script>
var random_number = Math.floor(Math.random() * 5 + 1);
document.write(random_number);
</script>

Other Tips & Tutorials

Vanilla Javascript

Display date and time using Javascript

Posted: 25th of July 2021

Views: 75

Vanilla Javascript

Clear all form fields using Javascript

Posted: 25th of October 2020

Views: 744

Vanilla Javascript

Generate a random number between 1 and 5 using Math.floor and Math.random commands in Javascript

Posted: 22nd of October 2018

Views: 1680

Vanilla Javascript

Using document.getElementByID() in javascript to send form data

Posted: 15th of October 2018

Views: 1505

Vanilla Javascript

Using document write() in javascript.

Posted: 14th of October 2018

Views: 1830