• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 231
  • Last Modified:

Working on Calender script

I am trying to work on a calender script I am using out a book for I can get to know Javascript and I have:

http://rksdesignstudios.com/files/cal/cal.htm

If you look in the error console on FF, I get:

Error: missing ) after condition
Source File: http://rksdesignstudios.com/files/cal/year.js
Line: 134, Column: 20
Source Code:
       if (calDate = null;){

_____________________

Error: yearly is not defined
Source File: http://rksdesignstudios.com/files/cal/cal.htm
Line: 42

JS:

http://rksdesignstudios.com/files/cal/year.js

First error:

function yearly(calDate){
       if (calDate = null;){
             var calenderDay == new Date();
       }else{
             var calenderDay == new Date(calenderDay);
             
       var currentTime == getTime(calenderDay);
      
       // pull 4 digit year
       var thisYear == calenderDay;


I am new at JS and I probably have several other errors that make no sense so excuse me and if you could help me with those that would be great.

Thanks in advance,

Ryan
0
catonthecouchproductions
Asked:
catonthecouchproductions
  • 10
  • 8
1 Solution
 
ncooCommented:
You should not have a semi-colon in a if.

So change:

if (calDate = null;){
to      
if (calDate == null){

You should also be using a == to compare two values.

When setting a value you should use a single =

So change:

var calenderDay == new Date();
to
var calenderDay = new Date();

var calenderDay == new Date(calenderDay);
to
var calenderDay = new Date(calenderDay);

var currentTime == getTime(calenderDay);
to
var currentTime = getTime(calenderDay);

var thisYear == calenderDay;
to
var thisYear = calenderDay;
0
 
catonthecouchproductionsAuthor Commented:
Thank you for that, simple mistake, haha.

I started making changes to the other stuff and I got those all on my own, but I am stuck here:

Error: missing ) after for-loop control
Source File: file:///Macintosh%20HD/Users/ryancoughlin/Documents/Client%20Side%20Scripting/tutorial%203/year.js
Line: 149, Column: 18
Source Code:
      for(i=1; i<3; i++;){

CODE:

for(i=1; i<3; i++;){
            document.write("<tr>");
            
            // named j that goes from 1-4 in increments of 1
            for(j=1; j=1<4; j++;){
                  
                  // increase by one
                  monthNum++;
                  
                  // use setDate() date object method to change the day value of calenderDay to 1 (first of month)
                  calenderDay.setDate(1);
                  
                  // use the setMonth() date object method to change the month value of calenderDay to monthNum
                  calenderDay.setMonth(monthNum):
                  
                  // call function
                  writeMonthCell(calenderDay, currentTime);

            }
            // write closing </tr> after nested loop
            document.write("<tr>");
      }

I also updated it remotely as well.

Ryan
0
 
ncooCommented:
With for loops you don't need the last semi-colon:

Change:

for(i=1; i<3; i++;){
to
for(i=1; i<3; i++){

for(j=1; j=1<4; j++;){
to
for(j=1; j=1<4; j++){

If might also be a good idea to decare the i and j as variables if you haven't previously in the script.

Just change the start of the for loop to include the var, like so.

for(var j=1; j=1<4; j++){
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
catonthecouchproductionsAuthor Commented:
Thanks for the advice, that got rid of those errors.

I have one more at the bottom of the page.

Error: missing } in compound statement
Source File: file:///Macintosh%20HD/Users/ryancoughlin/Documents/Client%20Side%20Scripting/tutorial%203/year.js
Line: 171, Column: 28
Source Code:
            document.write("</table>");

Any ideas on how to fix that? And i am getting:
Error: yearly is not defined
Source File: file:///Macintosh%20HD/Users/ryancoughlin/Documents/Client%20Side%20Scripting/tutorial%203/cal.htm
Line: 42

HTML:

   <script type="text/javascript">

   yearly(calDate);
   
   </script>
0
 
ncooCommented:
It looks like your missing the last two } from the yearly function, see below.  Should fix both problems.

function yearly(calDate){
       if (calDate == null){
             var calenderDay = new Date();
       }else{
             var calenderDay = new Date(calenderDay);
             
       var currentTime = getTime(calenderDay);
      
       // pull 4 digit year
       var thisYear = calenderDay;
      
          document.write("<table id='yearly_table'><tr><th id='yearly_table' colspan='4'>"+thisYear+"</th></tr>");
            
      var monthNum = -1;
      
      //named i that goes from 1-3 in increments of 1
      for(var i=1; i<3; i++){
            document.write("<tr>");
            
            // named j that goes from 1-4 in increments of 1
            for(var j=1; j=1<4; j++){
                  
                  // increase by one
                  monthNum++;
                  
                  // use setDate() date object method to change the day value of calenderDay to 1 (first of month)
                  calenderDay.setDate(1);
                  
                  // use the setMonth() date object method to change the month value of calenderDay to monthNum
                  calenderDay.setMonth(monthNum);
                  
                  // call function
                  writeMonthCell(calenderDay, currentTime);

            }
            // write closing </tr> after nested loop
            document.write("<tr>");
      }
            document.write("</table>");
}
}
0
 
catonthecouchproductionsAuthor Commented:
Very nice, that solved that, now i am getting calDate not defined, but I have:

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

Do i need to add:

var calDate = XXX;

or whatever?

Ryan
0
 
catonthecouchproductionsAuthor Commented:
Anyone have any suggestions on what I can do to fix that?

Thanks,

Ryan
0
 
ncooCommented:
When you call the function you are sending it calDate which has no value.

As bellow:

  <script type="text/javascript">

   yearly(calDate);
   
   </script>

Change it just to:

yearly();
0
 
ncooCommented:
That should be with the script tags still.
 
 <script type="text/javascript">

   yearly();
   
   </script>
0
 
catonthecouchproductionsAuthor Commented:
Thank you for that, I checked in the error console and I have no errors, but nothing shows on the page, any suggestions?

Ryan
0
 
ncooCommented:
I think you should have a look at this page on the Date Object.

http://www.w3schools.com/js/js_obj_date.asp

For instance have a look at this:

<script type="text/javascript">

var minutes = 1000*60
var hours = minutes*60
var days = hours*24
var years = days*365
var d = new Date()
var t = d.getTime()
var y = t/years

document.write("It's been: " + y + " years since 1970/01/01!")

</script>

In your code you have:
var currentTime = getTime(calenderDay);
You should have:
var currentTime = calenderDay.getTime();

Also when you set the date:
var calenderDay = new Date(calenderDay);
It should be:
var calenderDay =new Date();
calenderDay .setFullYear(2010,0,14);

Anyway have a look at that page.
0
 
catonthecouchproductionsAuthor Commented:
Thank you for that! I made those changes and still no output can you see what else is wrong?

Thanks,

Ryan
0
 
catonthecouchproductionsAuthor Commented:
What do I do with this line:

calenderDay .setFullYear(2010,0,14);

I have:

function yearly(calDate){
       if (calDate == null){
             var calenderDay = new Date();
       }else{
             var calenderDay = new Date();
             
            var currentTime = calenderDay.getTime();      
       // pull 4 digit year
       var thisYear = calenderDay;

Do I replace:

       // pull 4 digit year
       var thisYear = calenderDay;

With

calenderDay .setFullYear(2010,0,14);

0
 
catonthecouchproductionsAuthor Commented:
Hey, any other suggestions on why it isnt displaying? I am stuck I keep looking over my code and am clueless?

Thanks,

RYan
0
 
ncooCommented:
The problem I am having is I am not sure what you after doing.

For instance:

 // pull 4 digit year
var thisYear = calenderDay;

That doesn't make thisYear have the year value it will just have the same value as calenderDay.

Have a look at this page for a example of a calendar, it's great script.

http://www.garrett.nildram.co.uk/calendar/scw.htm#examples-demo
0
 
catonthecouchproductionsAuthor Commented:
Thank you! I will take a look at that page.

Any idea on how to get the four digit year?

Ryan
0
 
ncooCommented:
var thisYear = calenderDay.getFullYear();

For the other options swap getFullYear for one of the other gets below:

    * getTime() - Number of milliseconds since 1/1/1970 @ 12:00 AM
    * getSeconds() - Number of seconds (0-59)
    * getMinutes() - Number of minutes (0-59)
    * getHours() - Number of hours (0-23)
    * getDay() - Day of the week(0-6). 0 = Sunday, ... , 6 = Saturday
    * getDate() - Day of the month (0-31)
    * getMonth() - Number of month (0-11)
    * getFullYear() - The four digit year (1970-9999)
0
 
catonthecouchproductionsAuthor Commented:
Oh wow, I didnt know all of those, thank you.

I will try giving that a shot and seeing what I can do. If not, ill probably reply back here.

Thank you for your help.

Ryan
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 10
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now