"unqualifiied-id expected before"if" error

every time i try to compile my project it keeps giving me these errors. its my first time making something without a guide. Here’s the code:

const int pingPin=2;
const int ledpin=3;
const int beeppin=4;
const int slowflash=1000;
const int medflash=500;
const int fastflash=250;
const int superfastflash=100;
void setup(){
int nodetect=100;
int fardetect=80;
int meddetect=60;
int closedetect=40;
int veryclosedetect=20;
pinMode(ledpin,OUTPUT);
pinMode(beeppin,OUTPUT);
}

void loop(){
long duration, inches, cm;//detremine length
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);
inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);
delay(100);
}

long microsecondsToInches(long microseconds)
{
return microseconds / 74 / 2;
}

long microsecondsToCentimeters(long microseconds)
{
return microseconds / 29 / 2;
}

const int nodetect=100;
const int fardetect=80;
const int meddetect=60;
const int closedetect=40;
const int veryclosedetect=20;
if (microsecondsToInches >= nodetect){
digitalWrite(ledpin,HIGH);
delay(slowflash);
digitalWrite(ledpin,LOW)
delay(slowflash);
}
if (microsecondsToInches >= fardetect && (microsecondsToInches <= nodetect))
{
digitalWrite(ledpin,HIGH);
delay(medflash);
digitalWrite(ledpin,LOW);
delay(medflash);
}
if (microsecondsToInches >= meddetect && (microsecondsToInches <= fardetect))
{
digitalWrite(ledpin, HIGH);
delay (fastflash);
digitalWrite(ledpin,LOW);
delay(fastflash);
}
if (microsecondsToInches >= closedetect && (microsecondsToInches <= meddetect))
{
digitalWrite(ledpin,HIGH);
delay(superfastflash);
digitalWrite(ledpin,LOW);
delay(superfastflash);
}
if (microsecondsToInches >= veryclosedetect && (microsecondsToInches <= closedetect))
{
digitalWrite(beeppin, HIGH);
delay (superfastflash);
digitalWrite(beeppin,LOW);
delay(superfastflash);
}

  const int nodetect=100;
  const int fardetect=80;
  const int meddetect=60;
  const int closedetect=40;
  const int veryclosedetect=20;
  if (microsecondsToInches >= nodetect){
   digitalWrite(ledpin,HIGH);
   delay(slowflash);
   digitalWrite(ledpin,LOW)
   delay(slowflash);
  }
  if  (microsecondsToInches >= fardetect && (microsecondsToInches <= nodetect))
  {
   digitalWrite(ledpin,HIGH);
   delay(medflash);
   digitalWrite(ledpin,LOW);
   delay(medflash);
  }
  if  (microsecondsToInches >= meddetect && (microsecondsToInches <= fardetect))
  {
   digitalWrite(ledpin, HIGH);
   delay (fastflash);
   digitalWrite(ledpin,LOW);
   delay(fastflash);
  }  
  if (microsecondsToInches >= closedetect && (microsecondsToInches <= meddetect))
  {
   digitalWrite(ledpin,HIGH);
   delay(superfastflash);
   digitalWrite(ledpin,LOW);
   delay(superfastflash);
 }
  if (microsecondsToInches >= veryclosedetect && (microsecondsToInches <= closedetect))
  {
   digitalWrite(beeppin, HIGH);
   delay (superfastflash);
   digitalWrite(beeppin,LOW);
   delay(superfastflash);
 }

All that stuff needs to be inside a function.

You’ve declared a number of variables inside setup that you never use.

Please use CODE TAGS when posting code, do not use “format for forum” or whatever it is called