How to use JavaScript Math.random () in HTML p tag.

I’m trying to print 1 random number inside of me.

In HTML

JavaScript:

Function number ()

A

var minNumber = 1; // The minimum number you want.

var maxNumber = 5; // The maximum number you want.

var randomNumber = Math.floor (Math.random () * (maxNumber + 1) + minNumber); // Generates random numbers.

document.getElementById (“randomNum”). innerHTML = randomNumber; // Sets the content of the number.

False return // returns wrong to clear everything.

A

window.onload = Number 2 // Performs function on click.


HTML:

div class = card

div id = “randomNum”

h2> Header

p> Statistics – [randomNumber]

/ div

/ div

(I couldn’t get my HTML to post normally so I had to make it ugly. Sorry …)

My random number will be printed on the side, and it is unable to print further within the same p. I was wondering if there is a way to use JavaScript to put my random number in HTML inside my p and put all CSS settings in another div class card.

Thanks!

Add a Comment

Your email address will not be published. Required fields are marked *