\mathbb{Z}_n is cyclic, so to find what a homomorphism does to any element m in Zn, you only need to know what it does to 1, since 1 generates the group:
f(m) = f(1m)
= (f(1))m since f is a homomorphism
= am since we stipulated that f sends 1 to a
Note that normally, ab means that we multiply a, b times. However, when dealing with groups, it is common to refer to the group operation as multiplication (regardless of what it is - addition, addition mod n, multiplication, composition, etc.) and it is common to use "multiplicative notation," regardless of what the operation is. So 1m means that we do the group operation to 1, m times. The group operation happens to be addition modulo n, so we might prefer to write m(1) instead of 1m, but as long as you keep in mind that there is only one operation that concerns us, then the notation 1m meaning to add 1 to itself m times shouldn't confuse you.
Anyways, now you should be able to see that f must send m to am. There is only really one restriction that needs to be placed in order for f to be a function. Once this restriction is in place, not only will f be a function, but by the way we defined it, it will automatically be a homomorphism. Can you figure out this restriction? n need not divide the order of G. In fact, G could be an infinite group, in which case it may not even make sense to say whether n divides |G| or not.