React - Render Conditionally from Props

Tell us what’s happening:
Describe your issue in detail here.
i don’t know why this code is not working

  **Your code so far**
class Results extends React.Component {
constructor(props) {
  super(props);
}
render() {
  {/* Change code below this line */}
  return (
    <h1>
    {props.fiftyFifty ? "You Win!" : "You Lose!"}
    </h1>);
  {/* Change code above this line */}
}
}

class GameOfChance extends React.Component {
constructor(props) {
  super(props);
  this.state = {
    counter: 1
  };
  this.handleClick = this.handleClick.bind(this);
}
handleClick() {
  this.setState(prevState => {
    // Complete the return statement:
    return {
      counter: prevState.counter + 1
    }
  });
}
render() {
  const expression = math.random() >= 0.5 ? true : false // Change this line
  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>
  );
}
}
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36

Challenge: React - Render Conditionally from Props

Link to the challenge:

I try to remember what is this about…

    {props.fiftyFifty ? "You Win!" : "You Lose!"}

So when you instantiate the JSX for example as <Results fiftyFifty/> you access the properties inside a class using this.props.propName, right?

Thanks, this indeed , it was missing fron the child component.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.