What f1.8 lens do I buy for a Nikon D40?

What f1.8 lens do I buy for a Nikon D40?

The entry level D40 needs AF-S lenses if you intend to use the auto-focus feature.
If you do not mind manually focusing, any Nikkor AF lens will do
In your case of the AF-S 50 mm f/1.8 would be the choice

As it was mentioned, take care that you get a AF-S lens, not the cheaper AF ones.
The 50mm/1.8G AF-S is fine for portraits, the 35mm/1.8G AF-S is good for general low light street photography or group shots.
I own both lenses and mostly use the 50mm one - the 35mm lens is too much a compromise in terms of focal length for my liking.

35mm since D40 has a cropped sensor. The equivalent of 35mm to full frame is 52mm. The 50mm is too long for cropped sensors (75mm equivalent) unless you only want to do portraits. 35mm has more flexibility in terms of indoor shooting. And make sure it's AF-S. Otherwise it won't autofocus on your DSLR. Again, I'm talking about cropped sensors. Otherwise, 50mm is the clear choice.
Edit:
Forlorn, f1.8 is really special… Good in low light and nice creamy bokeh. I gotta ask, do you own a DSLR?

What ever one you can afford… And depends on what you are shooting…
do you HAVE to buy an f/1.8 lens? What is so special about f/1.8?
there are many good lenses that AREN'T f/1.8… Broaden your horizons…
[edit - and yet, f/1.7 and f/1.4 and f/0.95 are better at low light and "bokeh" than the f/1.8's… And depending on the photography, the lenses that are available - like telephoto don't have f/1.8 but f/2.8…
so without knowing WHAT the questioner is shooting, how can you recommend an "f/1.8 lens"?

I would buy a new camera first. The d40 has such low megapixels that you can never use it's photos anywhere except online. If you want to go somewhere with photography get a new camera like the d5000! I have a 50mm 1.8 and 35mm 1.8! I recommend the 35mm 1.8! Good luck!
my photos -

50mm F1.8 AF-S G (be careful not to buy the D version. The G version is 100% compatible with D40)
- I want to buy a Nikon D90. Do I buy from Best Buy or Crutchfield?
- I want to replace my Nikon D40 Lens. Which one shall i buy?
- Should I save up to buy the Nikon 50mm f/1.4 or buy 50mm f/1.8 lens?
- When you first buy a new nikon d810 body what are the best absolutely sharpe lens to buy?
- I need to buy a Nikon D40 battery?