I can figure out what is wrong with this simple sketch

Hi Guys I wondering what i did wrong with this sketch.

void setup() {
  // put your setup code here, to run once:
int delayTime = 1000;
Serial.begin (9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.println ("hello world");
  digitalWrite (2, HIGH);
  delay (delayTime);
  digitalWrite (2, LOW);
  delay (delayTime);
}

I get this when I compile it

type or paste code hereC:\Users\lotso\AppData\Local\Temp\.arduinoIDE-unsaved2025517-8488-1lmi8xx.fz8x\sketch_jun17a\sketch_jun17a.ino: In function 'void loop()':
C:\Users\lotso\AppData\Local\Temp\.arduinoIDE-unsaved2025517-8488-1lmi8xx.fz8x\sketch_jun17a\sketch_jun17a.ino:11:10: error: 'delayTime' was not declared in this scope
   11 |   delay (delayTime);
      |          ^~~~~~~~~
exit status 1

Compilation error: 'delayTime' was not declared in this scope

Was it the int syntax in setup?

delayTime must be declared outside of setup() or inside loop()

https://docs.arduino.cc/language-reference/en/variables/variable-scope-qualifiers/scope/

Ciao, Ale.

Ok thanks so all declarations need to be done outside of setup and loop then?

Read the link provided by @ilguargua.
It explains in detail

However most beginners just make all variables global and declare them at the top of the program outside of setup and loop, that way they can be used inside both setup and loop

Ok I assumed all Variables were global by default.
my esp32 seemed to upload the code and was working fine a few hours ago but now it just hangs saying this:-

Wrote 292768 bytes (157662 compressed) at 0x00010000 in 2.8 seconds (effective 825.9 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...
type or paste code here

Show the code you are now using.

int time1 = 1000;
void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.println ("hello world");
  digitalWrite (2, HIGH);
  delay (time1);
  digitalWrite (2, LOW);
  delay (time1);
}

How is that possible if your code never compiled?
Exactly what were you doing a few hours ago when it worked?

Do you think that the direction of DPin-2 should be configured?

And please, edit the title of your thread to reflect your intention (I can't ....).

I was doing other programs like a simple led blink then a serial write program (hello world) and watched it run through the serial monitor etc.
when I moved onto variables I had that problem we discussed.
It is writing to serial every 2 seconds, so it is working it just isn't setting pin 2 HIGH and LOW now. There is a lesson in this for me? the led might died.

didn't set pinMode function

Is it required?

Pins default to INPUT so if you want to output something you must use pinMode()

You should study the blink sketch and then read up on the purpose of each of the function in it.
All is explained here:
https://docs.arduino.cc/language-reference/

I will do thanks.
I was experimenting with the serial monitor.
in a Triangle Tech PLC you can change the value of a global variable like "A" with a serial monitor by typing A=A+1 or A= 4000 etc but that doesn't seem to be the case with this IDE. Thanks guys for helping me learn

The serial monitor has an input section where you can input numbers, letters, etc.
Spend some at the Arduino ref and try some of the examples.

Figure-1 shows various fields of the Serial Monitor of Arduino IDE.


Figure-1:

Interesting thanks

You have a lot to learn about the IDE and the programming language, don't be in a big hurry.
https://www.arduino.cc/en/Guide/