Different olfactory cues elicit distinct behaviors such as attraction, avoidance, feeding, or mating. In the nematode C. elegans, these cues are sensed by a small number of olfactory neurons, each of which expresses several different odorant receptors. The type of behavioral response elicited by an odorant could be specified by the olfactory receptor or by the olfactory neuron in which the receptor is activated. The attractive odorant diacetyl is detected by the receptor protein ODR-10, which is normally expressed in the AWA olfactory neurons. The repulsive odorant 2-nonanone is detected by the AWB olfactory neurons. Transgenic animals that express ODR-10 in AWB rather than AWA avoid diacetyl, while maintaining qualitatively normal responses to other attractive and repulsive odorants. Animals that express ODR-10 simultaneously in AWA and AWB have a defective response to diacetyl, possibly because of conflicting olfactory inputs. Thus, an animal's preference for an odor is defined by the sensory neurons that express a given odorant receptor molecule.