Render Conditionally from Props : Page Crashed

Tell us what’s happening:
The webpage crashed though i wrote the right code

Your code so far


class Results extends React.Component {
  constructor(props) {
    super(props);
    let a = Math.random() > .5;
  }
  
  render() {
    return (
    
      {(a == 1)? <Results fiftyFifty="You win!"/> : <Results fiftyFifty="You lose!"/> 
      }
    )
  };
};

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() {
    let expression = null; // change code here
    return (
      <div>
        <button onClick={this.handleClick}>Play Again</button>
        { /* change code below this line */ }
        <Results/>

        { /* change code above this line */ }
        <p>{'Turn: ' + this.state.counter}</p>
      </div>
    );
  }
};

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36.

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

Hi.
No, you didn’t write the right code.
Now:

  1. Why are you initializing a variable a in your Results component? What does a constructor function do and how you do you access variables initialized with a constructor? Why a simple a is undefined then? Do you need this variable initialized in Results component then?
  2. Why are you checking if a == 1 in your Results component? What does Math.random() return? And what does Math.random() > .5 return?
  3. Why are you calling <Results /> component from itself? What’s the purpose of this component?
  4. What is a prop and how do you access it? What (who) passes it and to whom?

Hopefully, once you can answer these questions, the solution will be easier to understand.

Edit: improved questions