Chosen Solution

The refrigerator works intermittently. When ever it stops working i slam the door hard and it will work again until it does the same thing again. I changed the capacitor and the switch. Same thing happens. Any tips or fixes anyone?

Could there be a frayed wire somewhere?

Sounds like a loose wire. Wait until it fails then go over the wiring with a multimeter looking for a break in continuity.