need help as iam newbee this programe is hanging on the middlle some times runs

exactly correct but unable to write button code

void loop()
{
val1 = digitalRead(switchPin1);
delay(50);
if (val1 == LOW) {digitalWrite(led0Pin, HIGH);
delay(1000);
digitalWrite(led0Pin, LOW);
delay(1000);
}