Hello, I am practicing React, and I like this challenge a lot, so I decided to add a new feature for counting the number of wins (it is long and stupid but I am wondering if there’s another way to do it, since I’ve tried to minimize errors as possible) :
You can substantially reduce the number of lines of code (my solution have 30 lines). You need to rethink your app so you didn’t have to repeat your code like you have done in the render method.
handleResult is repetitive too, you have to create only one handler for this app. You can “roll the dice” and set the state in the same handler and you can create a message in the state and set it depending on the result and then you can render it.
I can help you more if you want. Just try again and come back for a feedback.
Hi. I like that you have listened my tips but again you have a problem here:
You repeated almost the same set state in if and else statements. You can use ternary (conditional) operator. You are very close to the optimal solution. Give it another try and focus on the handlePlay function.
Hello Lauren !
I gave it another try, even though I thought it won’t work but it Did !!
I’m still a newbie in React, and I truly appreciate your help/tips !
so here it is (I hope I got the same as your solution lol) :
Okay, it’s nice to see how you improve your code. You can have only one set state for your app and you can use some variables. I’ll give you my solution because I see you got the idea how to work. I don’t have a lose counter but is very similar.