This is number memory game in Reactjs
The first number appears randomly. For example: 123.
The second number is what I will enter: 123.
That is correct.
So if I enter incorrectly for example 124, then 4 should be crossed out.
output should be like that:
<div>
<span>1</span>
<span>2</span>
<span className="wrong">4</span>
</div>
More example:
random_num: 4573
input: 4674
output: 4674
random_num: 4573
input: 4674761
output: 4674761
random_num: 123
input: 123456
output: 123456
>Solution :
Assuming you are passing both the entries as arrays to a component and let say array_1 is the original entry and array_2 is the second entry, then all you got to do is
function App({ array_1, array_2 }) {
return (
<div>
{array_2.map((val, i) => {
if (val === array_1[i]) {
return <span>{val}</span>;
}
return <span className="wrong">{val}</span>;
})}
</div>
);
}