Drawing two number, that must be the same

Hello, I making flashcard app and I have a problem with this code:

const word1 = document.querySelector('#word1');
const bt = document.querySelector('#bt');

function rand(){
	return Math.floor(Math.random() * 5);
}

word1.innerText = rand();
word2.innerText = rand();

bt.addEventListener("click", function(){
  word1.innerText = rand();
  word2.innerText = rand();
});

whole code
I want two numbers that I draw using the button to always be the same, how to do it?

the point is that in this code, the word that will appear after the “show” sticky has to agree. Sorry for my English if there are some issues. Thanks in advance for your answers.

Hi,

Like this?

bt.addEventListener("click", function(){
  const rand = rand();
  word1.innerText = rand;
  word2.innerText = rand;
});

Is that what you mean?

I foresee further problems with this idea.

Most likely, the OP is going to want an exhaustable set of values, rather than purely random ones.

An array, a shuffle, and a pop.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.