Use a Conditional in a Render Function

Copied the code because I can’t get this module to work. I am stuck, can anyone take a look and see if I am doing this right?

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 task;
    if (fiftyFifty===true) {
      task = 'out WOOO'
    } else {
      task = 'to bed WOOO'

    return <h1>Tonight I'm going{task}!</h1>;

the string returned should be an exact match, if we render TonightsPlan we can actually see something:

	<TonightsPlan />,

your output:

Tonight I'm goingto bed WOOO!

desired output:

Tonight I'm going to bed WOOO
1 Like

I actually changed it to this as well. I was stuck on it for so long but thank you for the reply!

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