...

View Full Version : Javascript function problem.



asharm27
03-18-2005, 05:56 PM
Hi,
I'm trying to make a website that is going to be used as a horoscope teller.

I have written the code below but when opening it in Internet Explorer (Service pack 2 installed) it comes up with an error message that says that there is something wrong with the code that will make the computer run slowly. Do I want to abort the script!

Does anyone know why this may be happening??

Any help would be appreciated greatly!!

Thanks again

Here is the script : -

<script type = "text/javascript">

var firstName, secondName, birthDate, birthMonth, findElement;

function findHoroscope () {
retrieveInput ();
checkDate ();
checkMonth ();
findStarsign ();
findElement ();
window.alert (firstName + " , your starsign is " + findStarsign + "and your element is " + findElement)
return;
}

function retrieveInput () {
firstName = document.starsign.first.value;
secondName = document.starsign.second.value;
birthDate = document.starsign.date.value;
birthMonth = document.starsign.month.value;
return; }

function checkDate () {
var birthDate = ((0<parseInt (document.starsign.date.value) && parseInt (document.starsign.date.value) <=31) ? true
:false);
if (birthDate == false) window.alert ("Problem with the date");
return birthDate; }

function checkMonth () {
var birthMonth = (document.starsign.month.value == "January" ? true
:document.starsign.month.value == "February" ? true
:document.starsign.month.value == "March" ? true
:document.starsign.month.value == "April" ? true
:document.starsign.month.value == "May" ? true
:document.starsign.month.value == "June" ? true
:document.starsign.month.value == "July" ? true
:document.starsign.month.value == "August" ? true
:document.starsign.month.value == "September" ? true
:document.starsign.month.value == "October" ? true
:document.starsign.month.value == "November" ? true
:document.starsign.month.value == "December" ? true
:false);

if (birthMonth == false) window.alert ("Problem with the month");
return birthMonth; }

function findStarsign () {
while ((checkDate == true) && (checkMonth == true));
var findStarsign = (
((birthDate == 21-31) && (birthMonth == "March"))?
"Aries" :
((birthDate == 1-19) && (birthMonth == "April"))?
"Aries" :
((birthDate == 20-30) && (birthMonth == "April"))?
"Taurus" :
((birthDate == 1-20) && (birthMonth == "May"))?
"Taurus" :
((birthDate == 21-31) && (birthMonth == "May"))?
"Gemini" :
((birthDate == 1-21) && (birthMonth == "June"))?
"Gemini" :
((birthDate == 22-30) && (birthMonth == "June"))?
"Cancer" :
((birthDate == 1-22) && (birthMonth == "July"))?
"Cancer":
((birthDate == 23-31) && (birthMonth == "July"))?
"Leo" :
((birthDate == 1-22) && (birthMonth == "August"))?
"Leo" :
((birthDate == 23-31) && (birthMonth == "August"))?
"Virgo" :
((birthDate == 1-22) && (birthMonth == "September"))?
"Virgo" :
((birthDate == 23-30) && (birthMonth == "September"))?
"Libra" :
((birthDate == 1-22) && (birthMonth == "October"))?
"Libra" :
((birthDate == 23-31) && (birthMonth == "October"))?
"Scorpio" :
((birthDate == 1-21) && (birthMonth == "November"))?
"Scorpio" :
((birthDate == 22-30) && (birthMonth == "November"))?
"Sagittarius" :
((birthDate == 1-21) && (birthMonth == "December"))?
"Sagittarius" :
((birthDate == 22-31) && (birthMonth == "December"))?
"Capricorn" :
((birthDate == 1-19) && (birthMonth == "January"))?
"Capricorn" :
((birthDate == 20-31) && (birthMonth == "January"))?
"Aquarius" :
((birthDate == 1-18) && (birthMonth == "February"))?
"Aquarius" :
((birthDate == 19-29) && (birthMonth == "February"))?
"Pisces" :
((birthDate == 1-20) && (birthMonth == "March"))?
"Pisces":
"Unable to find starsign - please check that your birth date and month is correct");

return findStarsign; }

function findElement () {

var findElement = ("Air" || "Earth" || "Water" || "Fire");

if (findElement == "Air")
while (findStarsign = ("Gemini" || "Libra" || "Aquarius"));
{return ("Air");} {
if (findElement == "Earth")
while (findStarsign = ("Taurus" || "Virgo" || "Capricorn"));
{return ("Earth");} {
if (findElement == "Water")
while (findStarsign = ("Cancer" || "Scorpio" || "Pisces"));
{return ("Water");} {
if (findElement == "Fire")
while (findStarsign = ("Aries" || "Leo" || "Sagittarius"));
{return ("Fire");}
} } } }

</script>

codegoboom
03-18-2005, 11:55 PM
Does anyone know why this may be happening??

Well, since it appears to be one gigantic, compounded, ternary expression, that might be the problem... ;)

Philip M
03-19-2005, 08:04 AM
There are in fact five basic elements - earth, air, fire, water and bull****.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum