BNewing / calculator

Javascript exercise
0 stars 0 forks source link

move code outside of if statement #2

Closed markdessain closed 8 years ago

markdessain commented 8 years ago

1. Repeated statement in if block

If you find yourself doing the same bit of code in every block in the if/else statement it often means it doesn't need to be apart of the if statement in the first place.

if(...) {
    a = b;
    ...
else if(...) {
    a = b;
    ...
else(...) {
    a = b;
    ...
}

can become:

if(...) {
    ...
else if(...) {
    ...
else(...) {
    ...
}
a = b;

You can see the File changed tab, as you're always changing the innerHtml no matter what the operation is.