Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

freecodecamp using props to render conditionally

class Results extends React.Component {
  constructor(props) {
    super(props);
  }
  render() {
    return (
      <h1>
      {this.props.fiftyFifty ? "You Win!" : "You Lose!"}
      </h1>
    )
  };
};

class GameOfChance extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      counter: 1
    }
    this.handleClick = this.handleClick.bind(this);
  }
  handleClick() {
    this.setState({
      counter: this.state.counter + 1 // change code here
    });
  }
  render() {
    const expression = Math.random() >= 0.5 ? true : false
    return (
      <div>
        <button onClick={this.handleClick}>Play Again</button>
        { /* change code below this line */ }
        <Results fiftyFifty={expression} />
        { /* change code above this line */ }
        <p>{'Turn: ' + this.state.counter}</p>
      </div>
    );
  }
};
Comment

PREVIOUS NEXT
Code Example
Javascript :: When defined as a method of an object, in a regular function this refers to the object 
Javascript :: _.extend Example 
Javascript :: suitescript render transaction 
Javascript :: https://graph.instagram.com/14.0/17841450694979740 
Javascript :: Backbone Sync And Fetch Example 
Javascript :: Another _extend Example 
Javascript :: onPlay 
Javascript :: Comparing mongoose _id and strings 
Javascript :: get file name with extension netsuite suitescript 
Javascript :: onSeek video getting paused 
Javascript :: prisma multiple queries in one query 
Javascript :: cannot read property of undefined js laravel mix 
Javascript :: add item or nothing array js 
Javascript :: sort array based on subarray value 
Javascript :: sort list by likes in javascript 
Javascript :: multiple populate on same level 
Javascript :: js Changing selected option by option id, class, or attribute 
Javascript :: external routes in nodejs api 
Javascript :: fib numbers javascript 
Javascript :: click page object 
Javascript :: v-smooth-scroll 
Javascript :: frompromise rxjs example 
Javascript :: javascript declaring variables 
Javascript :: how to change text of paragraph on click in java scriopt 
Javascript :: Plumasil - new item button desc text 
Javascript :: get number value from input e.target.value instead of string 
Javascript :: javascript Check the answer 
Javascript :: angularjs Both outer and inner divs have ng-click and when I click on the inner div, both ng-clicks execute. How to prevent that 
Javascript :: Issue in applying margin using angular "data-ng-style" 
Javascript :: How to map a JSON response with different indexes 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =