Simply, writing code is putting together a series of instructions to tell a computer what to do.
Imagine writing code as instructions, such as how to tie your shoes for someone who doesn't know:
Left, Right, Up, Down, Hold, Release, String, Shoe, Lacehole, In , Out etc
In more detail:
Writing code is part of the process of creating computer software. Computers have to be told what to do using a programming language. On a modern Mac, the most popular programming language is called "Objective C". On the internet, Java is a dominant programming language that allows you to play online games, chat with people around the world, calculate your mortgage interest, and view images in 3D, just to name a few.
Colloquially, the commands that make up a programming language are called code, so when a programmer writes software, he/she "writes code."
Programming languages have a lot in common with traditional, spoken languages like English or Spanish: there are rules about vocabulary, grammar, and syntax which the programmer must follow. Generally, the programmer starts with an idea about what he/she wants the program to do and then translates that idea to the programming language, much like an interpreter takes something a person says in one language and translates it to another. Programming languages are not as expressive as most spoken languages, so the translation process can be much more complex.