Help on a very short and simple code

I am making a reed switch alarm with a piezo alarm buzzer, so that the alarm will sound when the reed switch is activated. This is the code I wrote.

int ReedSwitch = 3
int buzzer = 8
int val = 0;
void setup() {
  pinMode(buzzer, OUTPUT);
  pinMode(ReedSwitch, INPUT);
}

void loop() {
  val = digitalRead(ReedSwitch);
  if val == HIGH  
{
  tone(buzzer, 1000);
  delay(1000);
  noTone(buzzer);
  delay(1000);
  
}
  else
{  
  noTone(buzzer);
}
}

If it isn't obvious enough already, this is my first time working and coding an arduino, the above code was barely put together by Googling. What problems are there with what I wrote?

Did you try to compile it? That will usually throw out any syntax errors.

Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is that the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. If your browser doesn't show the posting toolbar then you can just manually add the code tags:
[code]`` [color=blue]// your code is here[/color] ``[/code]
Using code tags and other important information is explained in the How to use this forum post. Please read it.

Please always do a Tools > Auto Format on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read. If you're using the Arduino Web Editor you will not have access to this useful tool. I recommend you to use the standard IDE instead.

dannable:
Did you try to compile it? That will usually throw out any syntax errors.

Nope, I guess I should wait for my parts to so that I can actually try the code and find errors that way. I posted this topic in hopes of correcting some obvious programming mistakes because there was still so much in the tutorials that I didn't understand.

Welp, I'll wait until then.

You can use the IDE to compile the program before your parts arrive. Obviously you can't perform the second stage, uploading, without the hardware.

I can see one error but it will be highlighted when you try to compile it. That will help you get a feel for problems and resolving them.

There are a couple of problems with the code, but as has been said they will show up when you compile it. It is, however, possible for a program to compile and still have problems.

It is also possible for there to be problems with the circuit associated with a program and this may be the case with yours. You are testing to see whether the input goes HIGH but is there anything keeping it LOW normally or is it floating at an uncertain voltage ? If not already present then a pulldown resistor to take the input to GND except when the switch is activated would be a wise precaution.

Even easier than adding an external resistor would be to use INPUT_PULLUP with the pinMode() to activate the internal pullup resistor and to change the circuit to take the input LOW when the switch is activated. The program will require a minor change too but the wiring will be neater than using an external resistor.

Missing semicolon's at the end of the variable's declarations (first two lines). If statement needs brackets.

Fixed the errors and verified using the web editor:

int ReedSwitch = 3;
int buzzer = 8;
int val = 0;
void setup() {
  pinMode(buzzer, OUTPUT);
  pinMode(ReedSwitch, INPUT);
}

void loop() {
  val = digitalRead(ReedSwitch);
  if (val == HIGH)
{
  tone(buzzer, 1000);
  delay(1000);
  noTone(buzzer);
  delay(1000);
  
}
  else
{  
  noTone(buzzer);
}
}