Think about which company's lenses are more desirable, and also the 40D can't shoot video. The 40D is faster and better for action, and built tougher. But like Jeremy said, the D90 is newer with higher resolution and slightly better IQ. Ultimately I would (and did) stretch to a refurbished 50D, but if you can't afford that I'd probably go with the Nikon between these two. The 40D is still good, but probably beyond the investment stage.

One important factor to consider when buying a DSLR is ergonomics. Tell your friend to try each camera out in his/her hands, navigate the camera's menus, and see which one feels better snapping photos and controlling the settings with.
It's also important to think about what lenses he'll/she'll use the most. Canon seems to have a bit of a better selection of telephoto lenses, so if your friend will be shooting sports, action or wildlife the 40D may be a better choice. However, Nikon has an excellent selection of wide angle lenses (plus, the Nikon has a slightly higher resolution), so the D90 may be a bit of a better choice for landscapes.

If I had to choose, I'd go with the D90, as it's newer, shoots video and has better image quality. However, if your friend prefers the ergonomics of the 40D it should be his/her choice.

Another option to consider is buying a brand new entry level camera, such as Nikon's D5100 or Canon's 600D (or the 550D to save some cash). Generally, they'll offer the same IQ (Image Quality) as the higher end camera like the 60D or D7000, but you're paying a lower price because they leave out features like a magnesium alloy body, a top LCD display, dedicated control buttons and generally have a smaller, dimmer viewfinder. If at the end of the day all that your friend really cares about is the IQ of his/her final photos, I'd definitely consider an entry level body. Also remember that if you buy a new body as opposed to a second hand body, you're guaranteed that the camera hasn't been dropped or abused, plus you get a warranty in case you get a lemon.

By the way, is video something that matters to your friend? If so, definitely go for Canon, something like the 600D would be perfect.

I'd skip the D80, it's lower resolution 10.1 MP CCD isn't a very good performer in low light, it doesn't have any sort of live view functionality, no video mode (if it matters to you), a smaller, much lower resolution display and it's 1.5 FPS faster. Besides, a D80 would quickly become outdated by today's standards, while a D90 won't become outdated for a few years now.

ive got a d90 and its awesome , great all round camera, excellent image quality, vast amount of settings to choose from,

biggest factor is going to be the lenses and where you want to go in the future, if you wanted to switch from nikon to cannon or vice versa you would have to sell all the lenses and buy again for the other format.