Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript

Bryant Feld
seal-mask
.a{fill-rule:evenodd;}techdegree
Bryant Feld
Full Stack JavaScript Techdegree Student 26,144 Points

react components managing state quiz - questions 5 & 6

I am entering what I am pretty sure are correct answers for the coding portion of this quiz but I keep failing the quiz based on the last two questions, the answers are pretty straight forward, I think there may be a glitch, can someone take a look and advise

I would recommend posting your code so others can take a look and help you out. Just remember to reference the Markdown Cheatsheet when posting a snippet of your code.

Bryant Feld
seal-mask
.a{fill-rule:evenodd;}techdegree
Bryant Feld
Full Stack JavaScript Techdegree Student 26,144 Points

Answer to question 5

class ControlledInput extends Component {
  state = {
    value: ' '
  };
  handleChange(e) {
    this.setState({ value: e.target.value });
  }
  render() {
    return (
      <input 
        type="text" 
        value={ this.state.value }   
        onchange={ this.handleChange }
      />
    );
  }
}
Bryant Feld
seal-mask
.a{fill-rule:evenodd;}techdegree
Bryant Feld
Full Stack JavaScript Techdegree Student 26,144 Points

answer to question 6

class Students extends Component {
  state = {
    students: [ // array of student objects ]
  };
  this.setState( prevState => ({
    students: [
       ...this.state.students,
      { // new student object }
    ]
  }));
  render() { ... }
}

2 Answers

Randy Layne
seal-mask
MOD
.a{fill-rule:evenodd;}techdegree seal-36
Randy Layne
Treehouse Moderator

Hi there Bryant, for question 5 Tanuki is absolutely correct, you just need to capitalize the 'C' in onChange. For question number 6, note that they are asking to bring the students in from the previous state, and that they have used the expanded form of the setState function that passes the prevState parameter to the function body. So, instead of using ...this.state.students, you would want to use ...prevState.students.

Hope this helps!

tanuki
tanuki
1,567 Points

Capital C in question 5.