Use a Conditional in a Render Function - fiftyFifty value not getting


#1

<PLEASE USE THIS TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/courses/react-101/lessons/react-components-advanced-jsx/exercises/render-function-if-statement?action=lesson_resume

<Below this line, in what way does your code behave incorrectly? Include ALL error messages.>

import React from 'react';
import ReactDOM from 'react-dom';

const fiftyFifty = Math.random() < 0.5;

// New component class starts here:
class TonightsPlan extends React.Component {
  render() {
    if (fiftyFifty) {
      
      return <h1>{fiftyFifty} Tonight I'm going out WOOO</h1>;
    } else {
      return <h1>{fiftyFifty} Tonight I'm going to bed WOOO</h1>;
    }
  }
}

ReactDOM.render(
	<TonightsPlan />,
	document.getElementById('app')
);

In return statement, I going to get value of fiftyFifty but it is value not appear…can you help me out to get value of this?


#2

I followed the example a little more closely than does your code.

import React from 'react';
import ReactDOM from 'react-dom';

const fiftyFifty = Math.random() < 0.5;

// New component class starts here:
class TonightsPlan extends React.Component {
  render() {
    let action;
    if (fiftyFifty) {
      action = 'out WOOO'
    } else {
      action = 'to bed WOOO'
    }

    return <h1>Tonight I'm going {action}!</h1>;
  }
}
ReactDOM.render(
  <TonightsPlan />,
  document.getElementById('app')
);

Your code will work but the SCT may not be expecting… {fiftyFifty}.


#3

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