OK, I will try one more time.
Still not right. = for assignment, == for comparison. If statement is a comparison. Read the reference.
How is the switch wired? A switch has 2 terminals. One goes to pin 2, where does the other go?
An open switch is "floating" so the state of the switch is random. You use a pullup or pulldown resistor (depending on how the switch is wired) to give the switch a known state when the switch is open. See this @Grumpy_Mike tutorial.