Animations

API

Arrays

Async

Basics

Challenges

Classes

Console

Dates

Debugging

DOM Elements

DOM Methods

DOM Navigation

DOM Properties

Event Listeners

Flow Control

Forms

Functions

Global Functions

JSON

Keywords

Libraries (3rd party)

Math

Modules

Objects

Snippets

String

Types

Widgets

Window Object

JavaScript - Random

Math.random() returns a random number. It returns a random number between 0 and a number lower than 1. Additional logic (like with Math.ceil() will be needed to return a random integer.

Tip: Math.ceil() and Math.random() can be used together to return a random number between 0 and 10.


let demo1 = document.getElementById("demo1");
demo1.innerHTML = "Random Number: " + (Math.ceil(Math.random() * 10));

http://www.w3schools.com/jsref/jsref_random.asp