Javascript help

well before getting into specifics can some1 tell me if there is any obvious problems with this code? (ps. im a noob at this :)

Quotefunction writeMonthCell(calenderDay, currentTime) {
document.write("<td class='yearly_months'>")
writeMonth(calenderDay, currentTime)
document.write("</td>")
}

function yearly(calDate) {
if (calDate == null) calenderDay=new Date() ;
else calenderDay= new Date(calDate);

var currentTime = calenderDay.getTime()
var thisYear = calenderDay.getFullYear()
document.write("<table id='yearly_table'>")
document.write("<tr>")
document.write("<th id='yearly_title' colspan='4' >")
document.write(+thisYear+)
document.write("</th>")
document.write("</tr>")

var monthNum = - 1
for(var i=1; i<=3; i++) {
document.write("<tr>");
for(var j=1; j<=4; j++) {
monthNum +;
calendarDay.setDate(1);
calenderDay.setMonth(monthNum) ;
writeMonthCell(calendarDay,currentTime);
}
document.write("</tr>")
}
document.write("</table>")

}

and use this cmd to call it
<script type="text/javascript">
yearly("June 7,2007");
</script>
Comments
19
use firebug to find out what's wrong with it
if (calDate == null) calenderDay=new Date() ;

if (calDate == null) {
calenderDay=new Date() ;
}
i changed that and still doesnt work :<
Parent
looks confusing :L
You're confusing
Parent
idd :)

i even sometimes confuse myself ;(
Parent
what doesn't work in it?

monthNum +;

should be monthNum++; ?
well what is suppost to happen (other scripsts not included since they given in question) is that a year calender with tables in tables...and nothing is appearing on the page so i did something wrong.

and i dont think it is monthNum ++ because in the book it says :
increase the value of munthNum by one
Parent
if you're increasing something by one, you use ++

where is 'writeMonth' function btw? you're calling it and i don't see its definion anywhere
Parent
is a variable
var monthNum = - 1
Parent
why don't u just use int instead of var?

(also in for-loops)
Parent
becasue i have no idea what that is :D
Parent
somehow I guessed that :p

well, int comes from Integer. So it's a variable type for integers (1,2,3...etc, also negative values).

U should use that when u are working with numbers. If u need decimal values, u should use type "double".

This var stuff doesn't look very good to me :p

Does a compiler compile it?
Parent
Does a compiler compile it?

what u mean by that lol?


so should i put int monthNum= -1 ?
Parent
I'm not expert at javascripts, but at least in normal java u need to compile them before they work. http://en.wikipedia.org/wiki/Java_compiler
And the compiler whines if there are errors in the code, and often shows where the errors are.

yes that notation with int is correct
Parent
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title></title>
</head>
<body>

<script language="JavaScript">
<!--
// vraag om twee getallen,
var getal1 = prompt('Typ een getal in: ', '0');
var getal2 = prompt('Typ nu een tweede getal in: ', '0');

//vergelijk de getallen
var groter = (getal1 > getal2);
var kleiner = (getal1 < getal2);
var gelijk = (getal1 == getal2);

//schrijf de resultaten naar het scherm
document.write('<h1>U voerde de getallen ' + getal1 + ' en ' + getal2 + ' in.</h1><hr>');
document.write('<h2>');
document.write('Is het eerste getal groter dan het tweede getal? : <font color="Red">', groter, '</font><br>');
document.write('Is het eerste getal kleiner dan het tweede getal? : <font color="Red">', kleiner, '</font><br>');
document.write('Is het eerste getal gelijk aan het tweede getal? : <font color="Green">', gelijk, '</font><br>');
document.write('</h2>');
//-->
</script>

</body>
</html>
just realized there are many errors and they are caused by you. first one is you forgetting how you named your variables. go through the code and debug it line by line

and half the code is missing, wherever you were copying it from, you failed at doing it :p
there are 6 other functions above this one.. i did not copy them because they were provided with the work and are right :)
Parent
so read the first part of my reply again
Parent
Back to top