GameOfChance Challenge Fail - working program

Tell us what’s happening:

Just curious why this is not accepted. It works, but does not pass the challenge. The solution shows the ternary expression inside GameOfChance, but the directions say to write the ternary inside of Results.

Your code so far


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() >= .5; // change code here
  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 (iPhone; CPU iPhone OS 13_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/21.0 Mobile/15E148 Safari/605.1.15.

Challenge: Render Conditionally from Props

Link to the challenge:
https://www.freecodecamp.org/learn/front-end-libraries/react/render-conditionally-from-props

Your code passed the challenge for me. Try using a different browser, preferably Chrome.

Yup. That worked. Thank you!

1 Like