lcd not declared in this scope???

plz what am i missing, this is a simple code or atleast should be..

code=
void setup() {
// put your setup code here, to run once:
//
#include <LiquidCrystal.h>

// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.print("20th century");
lcd.setCursor(0, 1);
lcd.print("FOX");
}

void loop() {

// put your main code here, to run rep
lcd.setCursor(8, 1);
// print the number of seconds since reset:
lcd.print(millis() / 1000);
}

error msg=

Arduino: 1.8.9 (Windows Store 1.8.21.0) (Windows 10), Board: "Arduino/Genuino Uno"

C:\Users\Christopher\Documents\Arduino\First_code\First_code.ino: In function 'void loop()':

First_code:21:4: error: 'lcd' was not declared in this scope

lcd.setCursor(8, 1);

^

exit status 1
'lcd' was not declared in this scope

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

#include <LiquidCrystal.h>

// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

All of that code belongs outside of setup(). Since you put the lcd constructor [LiquidCrystal lcd(rs, en, d4, d5, d6, d7);] inside of setup() it goes out of scope (no longer exists) when setup() finishes.

Libraries come with example sketches.

You can check these examples from within the IDE to see how things are done.

thank you i will try moving it from set up, the examples i copy pasted it from then changed it to both make it shorter, and to alter it were as im new to coding and using it for practice. thank you both for the help,

and Success , moving it before void setup() worked like a charm