It says my code is correct but the color isn't changing


#1

https://www.codecademy.com/courses/react-101/lessons/this-state/exercises/call-setstate-another-function?action=lesson_resume&link_content_target=interstitial_lesson

CodeAcademy is giving me a correct signal but when I click on the Change Color button, the background color does now change.



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

const green = '#39D1B4';
const yellow = '#FFD712';

class Toggle extends React.Component {
  constructor(props) {
  	super(props);
    this.state = { color: green};
  }
  
  changeColor() {
  	const newColor = this.state.color == green ? yellow : green;
    this.setState({ color: newColor });  
    this.changeColor = this.changeColor.bind(this);
  }
  
  render() {
    return (
      <div style={{background:this.state.color}}>
        <h1>
          Change my color
        </h1>
        <button onClick={this.changeColor}>
          Change color
        </button>
      </div>
    );
  }
}
ReactDOM.render (
	<Toggle />,
  document.getElementById('app')
);



#2

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