user31239: My circuit:

My code:
// Pin 13 has a LED connected on most Arduino boards.
// give it a name:
int led = 13;
const int buttonPin = 2; // pushbutton connected to pin 2.

// the setup routine runs once when you press reset:
void setup() {
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);
  pinMode(buttonPin, INPUT);
}

// the loop routine runs over and over again forever:
void loop() 
{
  bool buttonState = digitalRead(buttonPin);
  while (buttonState == HIGH) // check while the button is pressed
  {
   digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
   delay(1000);               // wait for a second
   digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
   delay(1000);               // wait for a second
  }
}

What I wish to do is that when I press the button, the Led's start flashing and when I press them again, they stop blinking (like a fire alarm). Right now they do nothing and I dont know why. Is it something with the circuit or the code?

user3466: The volatage level on the IO pin needs to change (from low to high and vice versa), only then can the microcontroller detect a button press. Without another connection to the button, IO2 is simply floating (unconnected).
There are two methods to implement this: external pull-up or external pull-down resistors and internal pull-up resistors (both methods are described for example in this tutorial).
I prefer the internal pull-up resitor method. You need to connect the second pin of the button to GND. Then change your setup code to
pinMode(buttonPin, INPUT_PULLUP);

If the button is not pressed, the internal pull up resistor inside the microcontroller pulls IO2 to +5V and a digitalRead(buttonPin) returns HIGH. When you press the button, IO2 is pulled to GND and digitalRead(buttonPin) returns LOW.
So in your case you need to check for a LOW reading, because you want the LEDs to blink when the button is pressed.
(Btw. you can replace the while loop with an if, since the loop() function is already executed in an infinite loop.)

31239: <p>My circuit:
<a href="https://i.stack.imgur.com/OAODo.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OAODo.jpg" alt="enter image description here"></a></p>

<p>My code:</p>

<pre><code>// Pin 13 has a LED connected on most Arduino boards.
// give it a name:
int led = 13;
const int buttonPin = 2; // pushbutton connected to pin 2.

// the setup routine runs once when you press reset:
void setup() {
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);
  pinMode(buttonPin, INPUT);
}

// the loop routine runs over and over again forever:
void loop() 
{
  bool buttonState = digitalRead(buttonPin);
  while (buttonState == HIGH) // check while the button is pressed
  {
   digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
   delay(1000);               // wait for a second
   digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
   delay(1000);               // wait for a second
  }
}
</code></pre>

<p>What I wish to do is that when I press the button, the Led's start flashing and when I press them again, they stop blinking (like a fire alarm). Right now they do nothing and I dont know why. Is it something with the circuit or the code?</p>
 3466: <p>The volatage level on the IO pin needs to change (from low to high and vice versa), only then can the microcontroller detect a button press. Without another connection to the button, IO2 is simply floating (unconnected).</p>

<p>There are two methods to implement this: external pull-up or external pull-down resistors and internal pull-up resistors (both methods are described for example in <a href="https://electrosome.com/switch-arduino-uno" rel="nofollow noreferrer">this tutorial</a>).</p>

<p>I prefer the internal pull-up resitor method. You need to connect the second pin of the button to GND. Then change your setup code to</p>

<pre><code>pinMode(buttonPin, INPUT_PULLUP);
</code></pre>

<p>If the button is not pressed, the internal pull up resistor inside the microcontroller pulls IO2 to +5V and a <code>digitalRead(buttonPin)</code> returns <code>HIGH</code>. When you press the button, IO2 is pulled to GND and <code>digitalRead(buttonPin)</code> returns <code>LOW</code>.</p>

<p>So in your case you need to check for a <code>LOW</code> reading, because you want the LEDs to blink when the button is pressed.</p>

<p>(Btw. you can replace the while loop with an if, since the <code>loop()</code> function is already executed in an infinite loop.)</p>
