My idea was to make a question and answer card game where when you click on a button you get a random question in a modal, all this works. My question is: How can I do so that the question that already came out does not appear again? for example if I get the question3, that it does not appear again in the whole game.
const Arrayorange = [
{
question: "question 1",
reply: "Reply 1",
},
{
question: "question 2",
reply: "Reply 2",
},
{
question: "question 3",
reply: "Reply 3",
}
];
export function Orange() {
const [stateModal, changeStateModal] = useState(false)
const [index, setIndex] = useState(0);
function openandchange(){
changeOrange();
openModal();
}
function changeOrange() {
let newIndex = Math.floor(Math.random() * (Arrayorange.length - 0) + 0);
setIndex(newIndex);
}
function openModal(){
changeStateModal(!stateModal)
}
const audio = new Audio(cardsound)
function openwithsound(){
openandchange();
audio.play()
}
return (
<div>
<button className="btn" onClick={openwithsound}><IoIosBody/></button>
<ModalOrange
state={stateModal}
changeState={changeStateModal}
titulo="Question"
>
<Content>
<h1>{Arrayorange.[index].question}</h1>
<p>{Arrayorange.[index].reply}</p>
</Content>
</ModalOrange>
</div>
)
}
Thank you very much for your answers in advance