Quotes help make search much faster. Example: "Practice Makes Perfect"

Tuesday, August 14, 2018

Codecademy Sample Solution: Use a Conditional in a Render Function


// sample solution to app.js

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) {
      task = 'out'
    } else {
      task = 'to bed'
    }

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

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

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts