The JavaScript library, project-1.js:
Code:
function Starship(Name,Length,Count,List){
// Create the Starship class.
this.name=Name;
this.length=Length;
this.numberConstructed=Count;
this.nameOfConstructedShips=List;
this.addConstructedShip=function(){
this.numberConstructed++;
}
this.getRandomName=function(){
alert(this.nameOfConstructedShips[Math.round(Math.random()*this.nameOfConstructedShips.length)]);
}
}
// Now let's make them.
gal_list=new array("Enterprise","Yamato","Venture","Galaxy","Odyssey","Challenger");
int_list=new array("Intrepid","Voyager");
enterprise=new Starship("Galaxy",641,6,gal_list);
voyager=new Starship("Intrepid",334,2,int_list);
The XHTML document:
Code:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<!-- This website is designed to conform with standards for XHTML 1.0 Strict. -->
<head>
<title>Objects</title>
<meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8" />
<script type="text/javascript" src="project-1.js">
</script>
<style type="text/css">
</style>
</head>
<body>
<script type="text/javascript">
document.write(enterprise.length);
</script>
</body>
</html>
Can someone tell me the problem? It should work... but no browser I use appears to like objects. I get an error saying that "enterprise is undefined"
Bookmarks