Tell us what’s happening:
I have written out the solution and everything seems to be working perfectly. however i still can’t get the last test to pass. I have no idea why. everything seems fine
Your code so far
class DisplayMessages extends React.Component {
constructor(props) {
super(props);
this.state = {
input: '',
messages: []
}
this.submitMessage= this.submitMessage.bind(this)
this.handleChange= this.handleChange.bind(this)
}
// add handleChange() and submitMessage() methods here
handleChange(event){
this.setState({
input: event.target.value
})
}
submitMessage(){
message: this.state.messages.push(this.state.input)
this.setState({
input: ''
})
console.log(this.state.messages)
console.log(this.state.input)
}
render() {
const listItems = this.state.messages.map((item,keys) =><li key={keys}>{item}</li>)
return (
<div>
<h2>Type in a new Message:</h2>
{ /* render an input, button, and ul here */ }
<input onChange={this.handleChange} value={this.state.input}></input>
<button onClick={this.submitMessage}>Add</button>
<ul>{listItems}</ul>
{ /* change code above this line */ }
</div>
);
}
};
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.81 Safari/537.36
.
Link to the challenge: