Welcome Guest!

If you do not have an account yet on The Web Squeeze forums, please Register! It’s FREE and there are many benefits:

  • Receive Fast Advice
  • Learn Programming Languages
  • Get Professional Website Reviews
  • Quick Troubleshooting Assistance

> Age Counter

This is a discussion on Age Counter, within the Javascript section. This forum and the thread "Age Counter" are both part of the Programming Your Website category.

 
Reply to this topicStart new topic
> Age Counter
acrikey
post Jun 2 2008, 05:05 AM
Post #1


Fresh Squeezed
**

Posts: 49
Joined: 30-March 08
From: Southern England


What have I done wrong?

CODE
<script>
// · Don't change anything here below ·

var age = new Date();
var day = age.getDate();
var year = age.getYear();
var month = (age.getMonth() + 1);
if (year < 1000) {
year += 1900;
}

// · Adjust values ·

var my_day = **2**;
var my_month = **6**;
var my_year = **1982**;
}

// · Don't change anything here below ·

if ((day == my_day) && (month == my_month)) {
my_age = year - my_year;
}
else if ((day >= my_day) && (month >= my_month)) {
my_age = year - my_year;
}
else if ((day < my_day) && (month == my_month)) {
my_age = --year - my_year;
}
else if ((day < my_day) && (month > my_month)) {
my_age = year - my_year;
}
else {
my_age = --year - my_year;
}
document.write (my_age);
</script>
Go to the top of the page
 
+Quote Post
Rakuli
post Jun 2 2008, 06:37 AM
Post #2


Squeeze Machine
Group Icon

Posts: 764
Joined: 13-February 08
From: Catching the squeezed drips downunder.


I think all the atserixes around your variable values would be your problem wink.gif

CODE
// · Adjust values ·

var my_day = **2**;
var my_month = **6**;
var my_year = **1982**;


Should be

CODE
// · Adjust values ·

var my_day = 2;
var my_month = 6;
var my_year = 1982;


--------------------
Luke Dingle . com

Turn Over a Playful Leaf on Web Design -- read about the javascript cat
Go to the top of the page
 
+Quote Post
acrikey
post Jun 2 2008, 06:43 AM
Post #3


Fresh Squeezed
**

Posts: 49
Joined: 30-March 08
From: Southern England


Still no change.

(Rakuli did you get me email?)
Go to the top of the page
 
+Quote Post
Rakuli
post Jun 2 2008, 07:01 AM
Post #4


Squeeze Machine
Group Icon

Posts: 764
Joined: 13-February 08
From: Catching the squeezed drips downunder.


I didn't really look much further than the asterixes at first. What is the code supposed to do?

PS. I got your email just now (it went to junk mail folder sorry) and have replied


--------------------
Luke Dingle . com

Turn Over a Playful Leaf on Web Design -- read about the javascript cat
Go to the top of the page
 
+Quote Post
Jason
post Jun 2 2008, 07:05 AM
Post #5


Master of the Universe
Group Icon

Posts: 1,298
Joined: 15-February 08
From: London, England


Have you looked at the Firefox debugger.

Tools->Error Console

Run page.


--------------------
Go to the top of the page
 
+Quote Post
acrikey
post Jun 2 2008, 07:12 AM
Post #6


Fresh Squeezed
**

Posts: 49
Joined: 30-March 08
From: Southern England


It is code to change someones age yearly
Go to the top of the page
 
+Quote Post
Rakuli
post Jun 2 2008, 07:20 AM
Post #7


Squeeze Machine
Group Icon

Posts: 764
Joined: 13-February 08
From: Catching the squeezed drips downunder.


You have a random stray curly brace

CODE
// · Adjust values ·

var my_day = **2**;
var my_month = **6**;
var my_year = **1982**;
} <---------Right here


That isn't needed. (as well as getting rid of the asterixes)


--------------------
Luke Dingle . com

Turn Over a Playful Leaf on Web Design -- read about the javascript cat
Go to the top of the page
 
+Quote Post
acrikey
post Jun 2 2008, 07:37 AM
Post #8


Fresh Squeezed
**

Posts: 49
Joined: 30-March 08
From: Southern England


Sorted thank you
Go to the top of the page
 
+Quote Post
If you found The Web Squeeze to be helpful, please donate so we can keep this site FREE, FRESH, and fortified with Web Design & Development info!
Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members: