Hi I'm trying to do some basic javascript and am getting "native code" instead of what I want:
<script type="text/javascript">
var today = new Date();
document.write(today + "<br />");
//document.write(today.length + "<br />"); - was getting "undefined"
//document.write(today[0] + "<br />"); - was getting "undefined"
document.write(today.getMonth + "<br />");
document.write(today.getMonth + "<br />");
document.write(today.getFullYear + "<br />");
</script>
output was:
Fri Jan 13 14:13:01 EST 2012
function getMonth() { [native code] }
function getDay() { [native code] }
function getFullYear() { [native code] }
what I want is to get the current Month, Day, Year and put it into an array variable that I will be able to call later on. I'm not getting far because of this native code. Can someone tell me what it is and hopefully, more importantly I can complete this project? Thank you for your time and help, it is much appreciated!
The getMonth
and the rest are functions, not properties, when you call just today.getMonth
you are getting a reference to the actual function. But, if you execute it using parenthesis, you get the actual result.
Your code should be:
document.write(today.getMonth() + "<br />");
document.write(today.getMonth() + "<br />");
document.write(today.getFullYear() + "<br />");
You are missing the parenthesis()
.
document.write(today.getMonth() + "<br />");
document.write(today.getMonth() + "<br />");
document.write(today.getFullYear() + "<br />");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With