0

This code works fine but it would be too long if the score is 50 or over. Is there any way to make it shorter and quicker? I tried to use for loop statement but it didn't work well.

  background(backgroundChange);
  if (score >= 5 && score < 10)
    backgroundChange-=0.8;
  else if (score >= 10 && score < 15)
    backgroundChange+=0.8;
  else if (score >= 15 && score < 20)
    backgroundChange-=0.8;
2
Contributors
3
Replies
6
Views
5 Years
Discussion Span
Last Post by JamesCherrill
2

OK, you could use the % operator to take the remainder after dividing score by 10.
Now all your values are 0-9 and you have only one test (>= 5) in a single if/then/else

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.