You are implying that evolution is somehow intelligent.
It is not.
This was already explained to you river.
You have a group of creatures (say, 100, for the sake of simplicity) that subsist by eating leaves off of the lower branches of certain trees.
Of this group, 50 are very similar, almost identical. 25 of them, for some reason, have longer necks. 25, for some reason, have shorter necks. Typically, this reason is a random genetic mutation.
These longer and shorter necks continue to be passed down to their offspring as they mate.
Suddenly, there is a very bad drought, and a lot of the trees shrivel, die, or are otherwise not producing leaves. On the remaining trees, the lower branches are quickly stripped away, both by these animals and by other herbivores. Food becomes scarce at the lower levels, and the short-neck animals begin to die off.
As the drought continues, most of the short-neck animals are dead, and now the 'normal' neck animals have eaten all the leaves THEY can reach, and they begin to die off.
By the time the rains come back, and the trees start to regrow, it is the long-necked variant of these creatures that have survived the best, and are slightly more populous. Additionally, many of the short and normal necked animals that were pregnant either died or miscarried because of the lack of food.
As the population regrows, there are considerably more long-necked variants, and the population has shifted, to where there are only 5 short necked, 45 normal necked, and 50 long necked.
A year or two goes by, and this weather pattern repeats. Before long, all that's left are the long-necked variety, which can reach all the leaves on the trees, not just the lower ones.
BAM, natural selection / evolution at work.
Oh, and now you have Giraffes.
Obviously the timeframes and quantity of animals were much, much larger... but this is, in essence, what happened, albeit on a much larger, much slower, and much longer lasting scale. There was also a secondary selection, in that, since giraffes use their necks while fighting over mates, those with longer, more powerful necks had the advantage and, much like colorful feathers on birds, were more desirable to females. Thus the longer-neck trait was passed along more frequently.
https://www.psychologicalscience.org/news/were-only-human/why-do-giraffes-have-long-necks.html
http://www.bbc.com/earth/story/20160629-giraffes-did-not-evolve-long-necks-to-reach-tall-trees