Home arrow static arrow Java Programming [Archive] - Help With This Code
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - Help With This Code
This topic has 2 replies on 1 page.

Posts:9
Registered: 5/8/04
Help With This Code  
Jul 30, 2004 11:34 AM



 
This is a basic script. Can someone tell me why its not working. I created an object called computer and then created a function. I added a call to the function to the computer object. It basically calculates the prices of different computer types based on the 3 parameters. None of my document.write commands are working except for the first 2, which basically writes only HTML. Here's the entire script.

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script Language="JavaScript">
<!--
function get_price()
{
var the_price=1000;
if (this.speed=="500MHz")
{
the_price+=200;
}
else
{
the_price+=100;
}
if (this.hdspace=="15GB")
{
the_price+=50;
}
else
{
the_price+=25;
}
if (this.ram=="128MB")
{
the_price+=150;
}
else
{
the_price+=75;
}
return the_price;
}

function computer(speed,hdspace,ram)
{
this.speed=speed;
this.hdspace=hdspace;
this.ram=ram;
this.price=the_price;
}

var work_computer= new computer("2GHz","80GB","1GB");
var home_computer= new computer("1.5GHz","40GB","512MB");
var laptop_computer= new computer("1GHz","20GB","256MB");

var work_computer_price= work_computer.price();
var home_computer_price= home_computer.price();
var laptop_computer_price= laptop_computer.price();

//-->
</script>
</head>

<body>
<script language="JavaScript">
<!--
document.write("<h2>The information on the computers you requested:</h2>");
document.write("<b>Work Computer: </b>");
document.write(work_computer.speed+","work_computer.hdspace","work_computer.ram"<br>");
document.write("<b>Total Cost</b>: $"+work_computer_price);

//-->

</script>
</body>
</html>

 

Posts:6,750
Registered: 1/25/04
Re: Help With This Code  
Jul 30, 2004 11:34 AM (reply 1 of 2)



 
This is a forum for Java, not JavaScript.
 

Posts:1
Registered: 7/30/04
Re: Help With This Code  
Jul 30, 2004 10:36 PM (reply 2 of 2)



 
you can go to some other forums about javascript
 
This topic has 2 replies on 1 page.