10 JSX Conditional


#1


10 JSX conditionals, If statements that do work.


Coin toss doesn't compile correctly. Can you find the what brackets or curly braces are incorrect?
Correct syntax is the word I'm looking for.

Replace this line with your code. 
var React = require('react');
var ReactDOM = require('react-dom');

if (user.age >= drinkingAge) {
  var message = (
    <h1>
      Hey, check out this alcoholic beverage!
    </h1>
  );
} else {
  var message = (
    <h1>
      Hey, check out these earrings I got at Claire's!
    </h1>
  );
  if (coinToss() == 'heads'){
  var img = <img src={pics.kitty} />; 
  }else{    
 var img = <img src={pics.doggy} />;    
     }
  
}

ReactDOM.render(
  message, 
  document.getElementById('app')
);


#3

On the second part of the question it tell you to do two things but apparently you miss understood,

"At the bottom of the file, call ReactDOM.render.

For ReactDOM.render's first argument, pass in img."


#4

The first part of this question is:

  if (coinToss() == 'heads'){
  var img = <img src={pics.kitty} />; 
  }else{    
 var img = <img src={pics.doggy} />;    
     }

#5

Not sure about the second one


#6

hello i'm trying to solve the exercice n10 in React JSX Conditionnals i can't find the solution
this is my code
if(coinToss() == "heads") {
var img = (

);
}else{
var img = (

);
}
Chris
and i got this error message Your condition should be if (coinToss() == "heads") {


#7

Your condition should be if (coinToss() == "heads") {

Still can't find my problem for coin toss.
Syntax placement is a mystery.
Do I need parentheses?


#8

Me too I didn't find the solution I tried this but no success :slight_smile:

if(coinToss() == "heads"){
var img = (
""
);
}else{
var img = (
""
);
}


#9

Hi! That happened with me also.

The solution is to put the code exactly as the console tells you to do. Use a space after if and in -> "heads") {

Also, it won't accept it if you use var img = ( );
You have to use var img = <img ... /> ;

regards


#10

It worked this way for me
if (coinToss() == "heads") {
var img = ;
} else {
var img = ;
}
ReactDOM.render(
img,
document.getElementById('app')
);


#11

It is true, to make the first part of the exercise to work you need to have a space between if and the paranthesis :

if (statement) etc...


#12

I found the problem thanks to you guys!
if() => cause the error
if () => this pass the compiler !
just need a "space" between if and ()


#13

This worked for me:

var React = require('react');
var ReactDOM = require('react-dom');

function coinToss () {
  // This function will randomly return either 'heads' or 'tails'.
  return Math.random() < 0.5 ? 'heads' : 'tails';
}

var pics = {
  kitty: 'https://s3.amazonaws.com/codecademy-content/courses/React/react_photo-kitty.jpg',
  doggy: 'https://s3.amazonaws.com/codecademy-content/courses/React/react_photo-puppy.jpeg'
};

// if/else statement begins here:
if (coinToss() == "heads") {
  var img = <img src={pics.kitty} />;
} else {
  var img = <img src={pics.doggy} />;
}

ReactDOM.render(img, document.getElementById('app'));

#14

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