Learn ReactJS - The ternary operator 11/16


#1

Hi! Can someone help me?

The instruction is:
On line 14, replace x, y, and z with the following three expressions. You have to decide which is x, which is y, and which is z:

‘doggy’

‘kitty’

coinToss() === ‘heads’
‘heads’ should return ‘kitty’, and ‘tails’ should return ‘doggy’.

Error message is:
Your ternary operator should look like coinToss() == ‘heads’ ? ‘kitty’ : ‘doggy’

https://www.codecademy.com/es/courses/react-101/lessons/react-jsx-advanced/exercises/jsx-conditionals-ternary?action=lesson_resume

```
import React from 'react';
import ReactDOM from 'react-dom';

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

const 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'
};

const img = <img src={pics[coinTos() === 'heads' ? 'kitty' : 'doggy']} />;

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

#2

in this line:

const img = <img src={pics[coinTos() === 'heads' ? 'kitty' : 'doggy']} />;

you misspelled coinToss, so javascript/react attempts to call a non-existing function, that doesn’t work


#3

I was searching for a more complicate error and it was really simple. Thank you!


#4

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