Files
Randell Dawson 1494a50123 fix(guide): restructure curriculum guide articles (#36501)
* fix: restructure certifications guide articles
* fix: added 3 dashes line before prob expl
* fix: added 3 dashes line before hints
* fix: added 3 dashes line before solutions
2019-07-24 13:29:27 +05:30

747 B

title
title
Render Conditionally from Props

Render Conditionally from Props


Solutions

Solution 1 (Click to Show/Hide)

Change handleClick() with proper increment statement.

handleClick() {
  this.setState({
    counter: this.state.counter + 1
  });
}

In render() method use Math.random() as mentioned in the challenge description and write a ternary expression to pass props in the Results component.

 let expression = Math.random() > .5;
    
{(expression == 1)? <Results fiftyFifty="You win!"/> : <Results fiftyFifty="You lose!"/> }

Then render the fiftyFifty props in the Results component.

  <h1>
  {
    this.props.fiftyFifty
  }
  </h1>