piezo buzzer with photo resistor

Hey I'm pretty new to arduino and am having trouble get the buzzer to stay completely silent whenever the light is blocked on the resistor, here's my code

const int photocellPin = A0; //photocell attach to
int sensorValue = 0; // value read from the sensor
const int buzzerPin = 9;
void setup()
{
pinMode(buzzerPin, OUTPUT); //initialize buzzer as an output
}
void loop()
{
sensorValue = analogRead(photocellPin); //read the value of A0
analogWrite(buzzerPin, 255); //
delay(sensorValue); //wait for a while,and the delay time depend on the sensorValue
analogWrite(buzzerPin, 0);
delay(sensorValue);

Is that the whole program ?

yup, thats all of it

newuser123:
yup, thats all of it

I am willing to bet that it isn't

In any case, why do you expect the buzzer to be silent when the LDR is covered ? Can you explain how you think the (nearly complete) program would do what you want ?

It seems to me that you should read the value returned from analogRead() and based on its value, sound the buzzer or not. Does your program do that ?