-1

inside a const :

<h2 className="logo" id="salt">{randomtext}</h2>

how do I have randomtext to show like "hi", "hello, "yes!" to show on a trigger ( let's say a button or so )

function randomtext() { ??
}
Alaa Zorkane
  • 13
  • 1
  • 6

1 Answers1

0

You should use Math.random js function have a random value in defined Array, here's a simple example:

function getRandomText() {
  const txts = ["hello", "bye", "see you", "mmm..."]
  let index = Math.round(Math.random() * (txts.length - 1))
  return txts[index]
}
let randomText = getRandomText()

$("#rText").html(randomText) 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="rText"></div>
Jordi Flores
  • 2,080
  • 10
  • 16