This application puts your memory to the test. You are presented with multiple images of Rick and Morty characters. The images get shuffled every-time they are clicked. You CAN NOT click on any image more than once or else your score resets to zero. The main objective is to get the highest score as possible or beat the game.
- Use lifecycle methods and React hooks such as useState and useEffect.
- Different uses of useEffect hook.
- Shuffle array
const shuffleArray = array => {
const arr = [...array];
let currentIndex = arr.length,
temporaryValue,
randomIndex;
// While there remain elements to shuffle...
while (0 !== currentIndex) {
// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
// And swap it with the current element.
temporaryValue = arr[currentIndex];
arr[currentIndex] = arr[randomIndex];
arr[randomIndex] = temporaryValue;
}
return arr;
};
- React
- Rick and Morty API