Experiment of comparator LM324
Here's another project to see how the comparator works.
You can adjust the input voltage with the control volume. When you turn it counterclockwise, LED 1 lights up and LED 2 goes out.
Now turn the control volume clockwise gradually... LED 2 lights up and LED 1 goes out at some point. At this point, the input voltage is the same as the reference voltage.... 4.5V.
Now, you've got the knack of the comparator operation. So, see what happens when the reference voltage is changed to 3 V or 6 V. Did you notice the change in the control setting at which the LEDs take turns lighting?