Created
January 19, 2017 01:50
-
-
Save jparrish62/d7e2c91d0f19cc288a1d6968aa8c709b to your computer and use it in GitHub Desktop.
I am trying to get all the cards to render out randomly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Hearts = React.createClass({ | |
getInitialState(){ | |
return { cards: [] } | |
}, | |
getCards(){ | |
this.setState({ | |
cards: [ | |
{ | |
four: <div className="outline shadow rounded red" onClick={this.flipCard}> | |
<div className="top"><span>4</span><span>♥</span></div> | |
<h1>♥</h1> | |
<div className="bottom"><span>♥</span><span>4</span></div> | |
</div> | |
}, | |
{ | |
three: <div className="outline shadow rounded red" onClick={this.flipCard}> | |
<div className="top"><span>3</span><span>♥</span></div> | |
<h1>♥</h1> | |
<div className="bottom"><span>♥</span><span>3</span></div> | |
</div> | |
}, | |
{ | |
two: <div className="outline shadow rounded red" onClick={this.shuffleCards}> | |
<div className="top"><span>2</span><span>♥</span></div> | |
<h1>♥</h1> | |
<div className="bottom"><span>♥</span><span>2</span></div> | |
</div> | |
}] | |
}); | |
}, | |
componentWillMount(){ | |
this.getCards(); | |
}, | |
render(){ | |
var dealtCards = this.state.cards | |
dealtCards.map(dealt => { | |
var myHearts = [dealt.two, dealt.three, dealt.four] | |
return ( | |
myHearts.sort(function () {return 0.5 - Math.random();}) | |
) | |
}); | |
return( | |
<div> | |
{myHearts} | |
</div> | |
) | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment