React - Use Advanced JavaScript in React Render Method

Tell us what’s happening:

When text is entered into the input element and the button is clicked, the MagicEightBall component should return a p element that contains a random element from the possibleAnswers array.

Your code so far

const inputStyle = {
  width: 235,
  margin: 5

class MagicEightBall extends React.Component {
  constructor(props) {
    this.state = {
      userInput: '',
      randomIndex: ''
    this.ask = this.ask.bind(this);
    this.handleChange = this.handleChange.bind(this);
  ask() {
    if (this.state.userInput) {
        randomIndex: Math.floor(Math.random() * 20),
        userInput: ''
  handleChange(event) {
  render() {
    const possibleAnswers = [
      'It is certain',
      'It is decidedly so',
      'Without a doubt',
      'Yes, definitely',
      'You may rely on it',
      'As I see it, yes',
      'Outlook good',
      'Signs point to yes',
      'Reply hazy try again',
      'Ask again later',
      'Better not tell you now',
      'Cannot predict now',
      'Concentrate and ask again',
      "Don't count on it",
      'My reply is no',
      'My sources say no',
      'Most likely',
      'Outlook not so good',
      'Very doubtful'
    const answer = possibleAnswers[Math.random() * possibleAnswers.length]; // Change this line
    return (
        <br />
        <button onClick={this.ask}>Ask the Magic Eight Ball!</button>
        <br />
          {/* Change code below this line */}
          {/* Change code above this line */}

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36 Edg/

Challenge Information:

React - Use Advanced JavaScript in React Render Method

The syntax on onlclick is incorrect at least to my knowledge. it should be code() as the value in quotation marks.
The other thing is you have two <br /> closing tags.

The syntax should be JSX since it is inside return()

1 Like

You should use the randomIndex state value as the index into possibleAnswers

Thank you for the help, I was able to solve that