Error - Random quote machine

Tell us what’s happening:

I am not able t understand why onClick event is not working in my project

Your code so far


Your browser information:

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

Challenge: Build a Random Quote Machine

Link to the challenge:

You didn’t bind the method (or use arrow syntax), also it should be this.state.index (const quote = quotes[this.state.index];)

@lasjorg but still my button onclick event not working

When you pass the getRandomIndex function to the button element you need to bind the ‘this’ to the function. Otherwise the function will use the ‘this’ referring to the button element itself and not the component class.

@DaxHarley thats working fine :+1:t3:. Thank U :slight_smile: