Why the LED freezes? when I am adding a delay? I am new into arduino and stuff. So i was playing around with the pull up resistor. It worked fine but the problem rised when I used a delay to turn the led on for few seconds before it gets back to low state it stopped working when I pressed the switch multiple times it may work sometimes but maximum time it is not working

here is the code

const int buttonPin = 4;     
const int ledPin =  12;     
int buttonState = 0;    


void setup() {
      pinMode(ledPin, OUTPUT);
      pinMode(buttonPin, INPUT_PULLUP);
}

void loop() {
        buttonState = digitalRead(buttonPin);
      if (buttonState == LOW) 
  {
    digitalWrite(ledPin, HIGH);
    delay(5000);
  } else 
  {
    digitalWrite(ledPin, LOW);
    delay(5000);
  }
}
Your Arduino does nothing during the delay(5000). So pressing the button during the 5000 mSec that the led is off won't do anything. Or you must be very lucky to press the button in the very small time between one loop and the next.

I learned a lot about timing and delays with this tutorial: Blink Without Delay