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;

Does that pattern repeat, eg score 35-40 change -=.8, score 40-45 change +=.8 etc ?

Yes that's right.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.