Why does my Nikon D40 not take as well pictures as a nikon D3100?
I'm using the 18-55mm lens and the pictures that my friend takes show a lot more quality. Is that due to the 4 more mega pixels?
Is it worth it upgrading to a D3100?
Your D40 should take perfectly fine images. I have a colleague who uses one professionally when he needs to sync with flash at speeds higher than 1/500th second. All his images are of professional quality.
Changing cameras will probably NOT improve your photography. Switch cameras with your friend sometime when you are out shooting together. My guess that his images are going to be just fine, no matter which camera he uses
On pixels
Read camera manual book carefully first.
It will be perhaps noticeable. The D40 had 6 Mp and the D3100 has 14Mp. Since that is more than double, it should be noticeable in some situations.
Check to see what your settings are; ISO, picture quality, picture size, and picture control (vivid, sharpness, etc).
http://www.althephoto.com