School Papers

import }}function cardsInitialize(){ return [ { name: “A”,

import React from ‘react’import ReactDOM from ‘react-dom’;export default function memorygame_init(root) {  ReactDOM.render(, root);}class MemoryGame extends React.Component{ constructor(props) { super(props); this.state = { gameCards: cardsInitialize(), disabled: false,  previousCard: ”, // To keep track of previous card matchdone: 0, //To keep count of matches done clicksPerformed: 0 //To calculate scores based on number of clicks }; this.displayCards = this.displayCards.bind(this); //try removing it    this.checkCardMatch = this.checkCardMatch.bind(this); //try removing it    this.restartGame = this.restartGame.bind(this); //try removing it } checkCardMatch(id,name){ let gameCards = this.state.gameCards; gameCardsid.flipped = true; this.setState({gameCards, disabled: true}); if(!this.state.previousCard){ this.setState({previousCard: {id, name},disabled: false});//try removing it } else{ if (name === this.state.previousCard.name) { let matchdone = this.state.matchdone; gameCardsid.match = true; gameCardsthis.state.previousCard.id.match = true; this.setState({gameCards, previousCard: null, disabled: false, matchdone: matchdone + 2, clicksPerformed: clicksPerformed + 1}); } else { setTimeout(() => {   gameCardsid.turned = false;   gameCardsthis.state.previousCard.id.turned = false;   this.setState({gameCards, previousCard: null, disabled: false, clicksPerformed: clicksPerformed + 1});   }, 1500); } } if (this.state.disabled) { return;   //try removing it } } displayCards(gameCards) { return gameCards.map((gameCard, index) => {   return ( //try removing it   ); }); }      restartGame() { this.setState({gameCards: cardsInitialize(), previousCard: null, disabled: false, matchdone: 0, clicksperformed: 0 });    } render() { var strRestart = ‘Restart Game’; var numScores; if (this.state.matchdone === this.state.gameCards.length) { if(this.state.clicksperformed === 8){ numScores = 100; } if(this.state.clicksperformed > 8 && this.state.clicksperformed 12){ numScores = 60; } } return (  

{this.displayCards(this.state.gameCards)}
  Scores Earned: {scores}
 

 

);    }}class GameCard extends React.Component {  constructor(props) {    super(props);    this.flipCard = this.flipCard.bind(this);  }  flipCard(params) {    if (!this.props.turned) {      this.props.checkCardMatch(this.props.id, this.props.name);    }  }  render() {    var classesCSS = classnames(‘Card’, {‘Card–flip’: this.props.turned}, {‘Card–match’: this.props.matched});    var strCardValue = this.props.turned ? this.props.name : ”;    return (     

We Will Write a Custom Essay Specifically
For You For Only $13.90/page!


order now
        {strCardValue}     

    );  }}function cardsInitialize(){  return { name: “A”, match: false, turned: false}, { name: “C”, match: false, turned: false}, { name: “B”, match: false, turned: false}, { name: “D”, match: false, turned: false}, { name: “A”, match: false, turned: false}, { name: “B”, match: false, turned: false}, { name: “C”, match: false, turned: false}, { name: “D”, match: false, turned: false}, { name: “E”, match: false, turned: false}, { name: “F”, match: false, turned: false}, { name: “H”, match: false, turned: false}, { name: “G”, match: false, turned: false}, { name: “F”, match: false, turned: false}, { name: “E”, match: false, turned: false}, { name: “G”, match: false, turned: false}, { name: “H”, match: false, turned: false},  ;}

x

Hi!
I'm Rhonda!

Would you like to get a custom essay? How about receiving a customized one?

Check it out