verify a sketch for me please.

hi, i'm new to this. could someone please tell me if my sketch is ok. i want to open a toggle switch to on, with 5volts on it(input). and at the outputs(22,24) sound an alarm and light up a led for 4 seconds. and in that four seconds it will sound and lite for a half second, that means 8 times, then stop with the switch still to on position. when i close it, i dont want nothing until i re-open it. i'm missing the half second delay???

thanks in advance, paul

/*
  Blink
  Turns on an LED and a alarm on for half second, then off for half second, repeatedly
  for 4 seconds and stops on high point ON.

 */
const int buttonPin = 23;     // the number of the toggle switch pin
const int ledPin =  22;      // the number of the 5volt bulb pin
 int buttonpin = 23;         // variable for reading the toggle status

void setup() {                
  // initialize the digital pins as an output and input.


  pinMode(22, OUTPUT);  
  pinMode(24, OUTPUT);
  pinMode(23,INPUT);
  
}

void loop() {
    int buttonpin=digitalRead(23);

     if (buttonPin == HIGH) {     
    // turn LED on:    
    digitalWrite(ledPin, HIGH);  
    digitalWrite(24,HIGH);
    delay(4000);
    digitalWrite(22,LOW);
    digitalWrite(24,LOW);
  } 
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW); 
    digitalWrite(24,LOW);
  }
}

Moderator edit: Please put code in code boxes. Use the # icon blah blah blah blah

const int buttonPin = 23;     // the number of the toggle switch pin
const int ledPin =  22;      // the number of the 5volt bulb pin
 int buttonpin = 23;         // variable for reading the toggle status

Using variable names that differ only by the case of one letter is really not a good idea.

The buttonPin name, for the name of a variable holding a pin number is not bad. Except that it isn't the number of a pin that a button is attached to. Buttons are attached to shirts. Switches are attached to Arduinos.

buttonpin as the name of the variable holding the state of a pin is a really lousy name.

  pinMode(23,INPUT);
    int buttonpin=digitalRead(23);

Why did you expend the effort to store the pin number in a variable, again?

There is no statement enabling the internal pullup resistor for the switch pin. This means that you are using an external resistor, right? The resistor is wired as a pulldown resistor, since you are testing for HIGH, right?

    digitalWrite(ledPin, HIGH);  
    digitalWrite(24,HIGH);
    delay(4000);
    digitalWrite(22,LOW);
    digitalWrite(24,LOW);

Inconsistency is not good. Why is ledPin used to turn the pin on, and the pin number used to turn the pin off? Why is pin 24 not given a meaningful identifier?

sound an alarm and light up a led for 4 seconds.

That's what the code above does.

and in that four seconds it will sound and lite for a half second, that means 8 times

Not the way the code is written it won't.

You need a for loop to execute 4 times, turning the ledPin and alarmPin (that's a nice name) on, pausing, turning them off, and pausing again.

then stop with the switch still to on position. when i close it, i dont want nothing until i re-open it.

You need to keep track of the previous switch state and the current switch state. Only perform the action when the current state is not equal to the previous state (a transition occurred - from pressed to released or from released to pressed) AND the current state is HIGH (pressed).