JSFiddle - React, Tailwind, and code Playground

by Slico

HTML

<p>The random number is <strong id='showRandom'></strong></p>
<p id='result'></p>
<button type='button' onclick='myNumber()'>Show the random number</button>

JavaScript

function myNumber() {
  // store the random number in the variable X
  var x = Math.floor((Math.random() * 10) + 1);
  
  // print the number in the showRandom ID
  document.getElementById('showRandom').innerHTML = x;
  
  // print the "the random number blablabla" in the same paragraph
  if (x == 5) { // 1 "=" is assign, not compare
    document.getElementById('result').innerHTML = 'The random number is 5!'
  }
  if (x < 5) {
    document.getElementById('result').innerHTML = 'The random number is less than 5!'
  }
  if (x > 5) {
    document.getElementById('result').innerHTML = 'The random number is greater than 5!'
  }
}