# React: Render Conditionally from Props -- Help Needed

**URL:** <https://forum.freecodecamp.org/t/react-render-conditionally-from-props-help-needed/240690>\
**Category:** General\
**Created:** [November 18, 2018, 2:54pm UTC](https://forum.freecodecamp.org/t/react-render-conditionally-from-props-help-needed/240690 "2018-11-18T14:54:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cobbmic](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/cobbmic/32/100182_2.png) [@cobbmic](https://forum.freecodecamp.org/u/cobbmic)\
**Post date:** [November 18, 2018, 2:54pm UTC](https://forum.freecodecamp.org/t/react-render-conditionally-from-props-help-needed/240690/1 "2018-11-18T14:54:52Z")

</div>

Here is what I have:

```auto
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() {
    let expression = Math.random > .5;
    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>
    );
  }
};

```

Everything passes except the last requirement: _When the `GameOfChance` component is first mounted to the DOM and each time the button is clicked thereafter, a single `h1` element should be returned that randomly renders either `You Win!` or `You Lose!` ._

When you click the “Play Again” button, it seems like there is not a new random number generated.

Is the component not rendered again (and so generating a different random number) whenever the button is clicked?

---

<div class="post-metadata">

**Author:** ![Layer](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/layer/32/82898_2.png) [@Layer](https://forum.freecodecamp.org/u/Layer)\
**Post date:** [November 18, 2018, 3:56pm UTC](https://forum.freecodecamp.org/t/react-render-conditionally-from-props-help-needed/240690/2 "2018-11-18T15:56:03Z")

</div>

> [@cobbmic](#):
>
> Math.random

`random` is a method and you have to execute if you want it to return a random number → `Math.random()`

---

<div class="post-metadata">

**Author:** ![dijo](https://avatars.discourse-cdn.com/v4/letter/d/eada6e/32.png) [@dijo](https://forum.freecodecamp.org/u/dijo)\
**Post date:** [January 17, 2019, 9:38pm UTC](https://forum.freecodecamp.org/t/react-render-conditionally-from-props-help-needed/240690/3 "2019-01-17T21:38:45Z")

</div>

what you pointed out is a bug indeed but it will not fix the problem either. I had the same problem here that the component will not be rendered again after pressing the button

---

<div class="post-metadata">

**Author:** ![Layer](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/layer/32/82898_2.png) [@Layer](https://forum.freecodecamp.org/u/Layer)\
**Post date:** [January 18, 2019, 9:00am UTC](https://forum.freecodecamp.org/t/react-render-conditionally-from-props-help-needed/240690/4 "2019-01-18T09:00:33Z")

</div>

Experiment the same error does not mean the source is the same ^^ (btw with the op code the problem is that the expression evaluate always to false, not a render issue ^^ )

Executing the `random` method is enough to let the OP code pass all the tests, if your code cannot pass the challenge please post it so we can help with it ( the link to the challenge is welcome too 😛 )

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 17, 2021, 8:06pm UTC](https://forum.freecodecamp.org/t/react-render-conditionally-from-props-help-needed/240690/5 "2021-01-17T20:06:57Z")

</div>

Closed on January 17, 2021, 8:06pm UTC


