0
Okay, I was curious and went to look for this exercise in code Academy.
The truth is: your code is right and is a valid way to solve the problem, but code Academy is waiting for something more basic, less correct.
What the site expects/accepts is:
var printS;
if (fiftyFifty) {
printS = <h1>Tonight I'm going out WOOO</h1>
} else {
printS = <h1>Tonight I'm going to bed WOOO</h1>
}
return printS;
That is, instead of looking for the piece of the string that changes with the condition and interpolate as they have in the example TodayPlan.js
on the line return <h1>Today I am going to {task}!</h1>;
, exercise looks for code in the format I put on top.
Remember that Code Academy is a site where a robot analyzes the code entered. And if no one writes all the possible variants, many of them are left out and give negative results on the test.
In short: your way is correct and much better than the way the site accepts as correct.
The code that worked for me:
var React = require('react');
var ReactDOM = require('react-dom');
var fiftyFifty = Math.random() < 0.5;
// React.createClass call begins here:
var TonightsPlan = React.createClass({
render: function () {
var printS;
if (fiftyFifty) {
printS = <h1>Tonight I'm going out WOOO</h1>
} else {
printS = <h1>Tonight I'm going to bed WOOO</h1>
}
return printS;
}
});
ReactDOM.render(
<TonightsPlan />,
document.getElementById('app')
);