Code question, going absolutely bonkes

I have a weird issue.

I have four buttons hooked up on A0.
(example https://www.the-diy-life.com/multiple-push-buttons-on-one-arduino-input/).

It only works with 1 IF. With other values the led is very dim (but does react).

The serial monitor does recoqnize the right values and I tried both polarities (button to positive and to negative). Serial monitor keeps reading the right values but only 1 IF gives a bright LED.

So for some reason when I enable more than one IF, I get no 5V.

I tried multiple digital pins as well.

Code below (I have been testing so not beautiful coding)

WTF am I doing wrong? As you can see I disabled all but one IF, now I get a LED bright. If I enable another it goes wild. Why?

//Michael Klements
//The DIY Life
//17 May 2019 
 
int ledPin = 10;    // choose the pin for the LED
int buttonValue = 0;
 
void setup()
{
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);   // declare LED as output
  pinMode(A0, INPUT);
}
 
void loop()
{
Serial.println(buttonValue);  
  buttonValue = analogRead(A0);  //Read in the button value
  //if (buttonValue>=1009 && buttonValue<=1020)  //Switch the LED on if button is pressed
   // digitalWrite(ledPin, HIGH);
  if (buttonValue>=80 && buttonValue<=100)
    digitalWrite(ledPin, HIGH);
  //if (buttonValue>=984 && buttonValue<=997)
  //  digitalWrite(ledPin, HIGH);
  //if (buttonValue>=953 && buttonValue<=982)
  //  digitalWrite(ledPin, HIGH);
  //if (buttonValue>=910 && buttonValue<=951)
  // digitalWrite(ledPin, HIGH);
  else
    digitalWrite(ledPin, LOW);  //Switch the LED off if button is not pressed
//delay(2000);
    
}

If I remove the last ELSE I get bright Led's but ofcourse, the will remain lit.

Also, if I use Else IF it works as well.

Did the author made a screw up? Or is the code that old that I cannot use it anymore? Or am I missing something else?

The else only belongs to the final if, so unless that if returns true then the LED will be taken LOW no matter how many other of the other ifs returns true

Ah, I already thought so. Thats why the else if works.

Thanks, I will take another look at the code.

Again, thanks Karma UP friend!

I think you meant to use "else if" rather than "if" for the subsequent tests.

You want the led to switch off only if no tests match? Current it switches off if the last test fails, even if previous ones succeed - in which case the led gets turned on by the test and immediately off again.

Yes, Thanks.

Wonder why the author wrote it this way.