Welcome to JustAnswer!
I am Pete, and I'll be happy to assist with your question.
The Nikon D3100 battery is held in by the battery door.
If the camera will only take a few photos before the battery appears to die, then the following may be causing this:
1. A bad battery - try using a replacement battery and see if that improves the camera's performance.
2. A bad battery connection - try cleaning the battery contact terminals inside the camera to remove any dirt or corrosion that may be preventing a good connection.
3. Faulty charge detection circuitry - if the camera's charge detection circuitry is faulty, it will mistakenly think that the battery is faulty and automatically turn off.
Test the battery with a voltmeter after the camera turns off - if the voltage reading is normal (around 3.7V) then the camera has a fault and will need to be returned to Nikon for repair.