...

View Full Version : Someone plzzz help with script code!!!



Bojangles69
04-26-2006, 03:17 AM
ive managed to keep a B in this class only because the test are multiple choice, but when it comes to writing code i can understand it after its wrote but have a hard time with logic.(plus im right brain dominant) but this is what i was given as a template, that needs to be modified. The goal is to prompt someone for the year they were born, find out how old they are with a date object and a basic function, then it displays the age, and last part is with an if statement, if the persons age is over 40 it has to change the bgcolor to red. The thing is this template seems so far from what i need i cant figure out how to modify it or start from scratch...

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> AGE CALCULATOR </TITLE>
<script>
var startTime = new Date();
var startInt = startTime.getTime();
var elapsedTime = new Date();
function getTime()
{
var output ="";
currentTime=new Date();
var currentInt = currentInt - startInt;
var elapsedInt = currentInt - startInt;
elapsedTime = new Date (elapsedInt);
output += elapsedTime.getMinutes()+":";
output += elapsedTime.getMilliseconds()+"\n";
document.myForm.txtOutput.value +=output;
}
</script>
</HEAD>
<BODY bgcolor=tan text=black>
<h1><center><b>Date Object</b></center>
<hr><hr>
</h1>
<center>
<form name="myForm">
<table border=4>
<tr>
<td><input type="button" value="Get Time"
onClick="getTime()">
</td>
<td><input type="text" name="textOutput">
</td>
</tr>
</HTML>
</table>
</form>
</body>

//main thing is i dont understand how the new Date getYear commands work,
i assume i prompt for year, get the current year and subtract difference, than a simple if statement for bgcolor, but i just cant apply it. Someone plzzz help!!!!!!!

Bojangles69
04-26-2006, 03:33 AM
ok without using the Date objects this is what i have..

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<h1> AGE CALCULATOR </H1>
</HEAD>
<BODY bgcolor =blue text=green>
<SCRIPT>
var year
var curryear=2006
var difference

//function bgcolor

year=prompt("Enter Year You Were Born")
year=eval(year)
difference= curryear - year
alert(difference)

if (difference < 40)
{

}



</script>
<body bgcolor = red>
</BODY>
</HTML>

does anyone at least know what i have to put between the brackets to get the bgcolor to change to red?? do i use a function?? im not sure how..

Bojangles69
04-26-2006, 04:22 AM
it was through trial and error, nothing more, no real logic, just a lot of guessing, but now i makes sense. ill be back with more questions next week. :D

<SCRIPT>

var year
var myDate =new Date()
var difference

year=prompt("Enter Year You Were Born")
year=eval(year)
alert("Thank You")
myDate=(myDate.getYear())
difference= myDate - year
alert("You are " + difference + " years old")

if (difference > 40)
document.bgColor="red"

//so simple i wanna scream

felgall
04-26-2006, 07:21 AM
The more correct way to do it would be:

document.getElementsByTagName('body')[0].style.backgroundColor = '#f00';

That bgcolor attribute has already been long deprecated and may not exist in the next generation of browsers.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum