Use && for a More Concise Conditional helppp

what is wrong with my code

Your code so far

class MyComponent extends React.Component {
  constructor(props) {
    this.state = {
      display: true
    this.toggleDisplay = this.toggleDisplay.bind(this);
  toggleDisplay() {
      display: !this.state.display
  render() {
    // change code below this line
    {this.state.display   &&  <h1>Displayed!</h1>}
    return (
         <button onClick={this.toggleDisplay}>Toggle Display</button>

Your browser information:

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

Link to the challenge:

@Hamzah98, there’s an h1 element in the code already. Do you mean for there to be two h1 elements?

i mean to type the conditional that if display is true then h1 should display

@Hamzah98 Consider replacing the existing h1 instead of creating a new one.

1 Like

Another aproach could be, assing a new variable with ternary conditional and that variable used into the render()

Something like this :wink:

const superpan = this.state.display ? '<p>Help me superpan!</p>' : null;

Finally, you are able to use this variable with braces into the return() jsx :eyes: