lgm432
10-05-2008, 07:55 PM
I have been reading through a book on javascript and I am trying to use a code I found in it.
This is what I have in the head.
<script language="JavaScript">
<!--
function get_price()
{
var the_price=1000;
if (this.speed == '500 MHz')
the_price+=100;
else
the_price+=200;
if (this.hdspace == '15 GB')
the_price+=50;
else
the_price+=25;
if (this.ram == '128 MB')
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=get_price;
}
var work_computer= new computer('2 GHz' , '80 GB' , 1 GB');
var home_computer= new computer('1.5 GHz' , '40 GB' , '512 MB');
var laptop_computer= new computer('1 GHz' , '20 GB' , '256 MB');
var work_computer_price= work_computer.price();
var home_computer_price= home_computer.price();
var laptop_computer_price= laptop_computer.price();
//-->
</script>
In the body I have a bunch of document.write with the variables located inside. The book was written in 2004 so is it a problem with the edition of the Javascript code or just a mistake I have made?
This is what I have in the head.
<script language="JavaScript">
<!--
function get_price()
{
var the_price=1000;
if (this.speed == '500 MHz')
the_price+=100;
else
the_price+=200;
if (this.hdspace == '15 GB')
the_price+=50;
else
the_price+=25;
if (this.ram == '128 MB')
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=get_price;
}
var work_computer= new computer('2 GHz' , '80 GB' , 1 GB');
var home_computer= new computer('1.5 GHz' , '40 GB' , '512 MB');
var laptop_computer= new computer('1 GHz' , '20 GB' , '256 MB');
var work_computer_price= work_computer.price();
var home_computer_price= home_computer.price();
var laptop_computer_price= laptop_computer.price();
//-->
</script>
In the body I have a bunch of document.write with the variables located inside. The book was written in 2004 so is it a problem with the edition of the Javascript code or just a mistake I have made?