8/16 Event Listeners: Attribute added, code works but does not pass


#1

I've added the attribute according to the instructions and example, the image changes to a dog when I click it, yet I receive the following error:

"The img should have an attribute of onClick={makeDoggy}."

Am I missing something here? It seems pretty straightforward, yet here I am.

Code:

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

function makeDoggy (e) {
  // Call this extremely useful function on an <img>.
  // The <img> will become a picture of a doggy.
  e.target.setAttribute('src', 'https://s3.amazonaws.com/codecademy-content/courses/React/react_photo-puppy.jpeg');
  e.target.setAttribute('alt', 'doggy');
}

var kitty = (
  <img
    src="https://s3.amazonaws.com/codecademy-content/courses/React/react_photo-kitty.jpg"
    alt="kitty"
    onClick={makeDoggy}
  />
);

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


#2

I just reset the exercise and worked through it again. It worked this time. Only minor differences in whitespace this time. Not sure if that really made any difference or why it failed the first 10 times I tried

var kitty = (
	<img 
		src="https://s3.amazonaws.com/codecademy-content/courses/React/react_photo-kitty.jpg" 
		alt="kitty" onClick={makeDoggy} />
);

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

Moving on...


#3

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