Codecademy React.js doubt

Asked

Viewed 55 times

0

I’m doing the React.js exercises at Codecademy.com and I got caught up in this issue. I don’t know what’s wrong and I can’t move forward.

inserir a descrição da imagem aqui

1 answer

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.json 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')
);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.