Category: Vanilla Javascript

Added: 22nd of October 2018

Viewed: 1253 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

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

Posted: 22nd of October 2018

Views: 1253

Vanilla Javascript

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

Posted: 15th of October 2018

Views: 1145

Vanilla Javascript

Using document write() in javascript.

Posted: 14th of October 2018

Views: 1435