Toy which can learn, behave according to pattern, and alter its actions depending on environmental stimuli using on-board electronics