Yes, you are writing the num_cow variable to the page on page load, at the time of page load, num_cow is undefined (your top line), it isn't truly defined until the div is clicked.
Instead you likely want to do this
<script>var num_cow = 0;</script>
<div class="green_button_1_class_1 ">ADD TO YOUR FARM</div>
// increment the Cow variable
num_cow = num_cow + 1;