The frequency-dependent polarizabilities and hyperpolarizabilities of HF, CO, H2O and para-nitroaniline calculated by density-functional theory are compared with accurate coupled-cluster results. Whereas the local-density approximation and the generalized gradient approximation (BLYP) perform very similarly and overestimate polarizabilities and, in particular, the hyperpolarizabilities, hybrid density-functional theory (B3LYP) performs better and produces results similar to those obtained by coupled-cluster singles-and-doubles theory. Comparisons are also made for singlet excitation energies, calculated using linear response theory.