Basically the closer you get, the quitter the alarm gets, but it should not be using digitalWrite. Instead it should be using analogWrite and a pin that supports PWM.
That code is total tosh.
It will not compile and has no terminating ;
With digital write you can only write high or low to a pin.
the code should / could be:-
if (distance < 20) // if the distance is less than 20
digitalWrite(buzzer, HIGH); // then turn on the buzzer