Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify boolean logic #5

Open
oliverjam opened this issue May 31, 2019 · 1 comment
Open

Simplify boolean logic #5

oliverjam opened this issue May 31, 2019 · 1 comment

Comments

@oliverjam
Copy link

You can generally eliminate a lot of if/else boilerplate by leveraging the fact that the strict equality comparison (===) will return a boolean.

E.g. you could replace this:

if (answer === correct_answer) {
setCorrect(true);
} else {
setCorrect(false);
}

with just

setCorrect(answer === correct_answer);
@sofiapoh
Copy link

Similarly to Oli, I noticed you were using a string "correct" as the initial value for your state:
https://github.com/FAC-Sixteen/b-b/blob/master/src/components/questionContainer/index.js#L9
When the type of the state is always going to be a boolean, it's a good idea to initialise it to a boolean too :) In this case false would had been a good initial state.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants