/*
JavaScript: A Beginner's Guide, Second Edition
By John Pollock
Publisher: McGraw-Hill,
Published December 2003, 550 pages,
ISBN 0072227907
*/
<HTML>
<HEAD>
<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=get_price;
}
var work_computer= new computer("500mHz","15GB","128MB");
var home_computer= new computer("450mHz","10GB","64MB");
var laptop_computer= new computer("350mHz","7GB","32MB");
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);
document.write("<BR>");
document.write("<B>Price:</B> $"+work_computer_price);
document.write("<P>");
document.write("<B>Home Computer: </B>");
document.write(home_computer.speed+","+home_computer.hdspace+","+home_computer.ram);
document.write("<BR>");
document.write("<B>Price:</B> $"+home_computer_price);
document.write("<P>");
document.write("<B>Laptop Computer: </B>");
document.write(laptop_computer.speed+","+laptop_computer.hdspace+","+laptop_computer.ram);
document.write("<BR>");
document.write("<B>Price:</B> $"+laptop_computer_price);
//-->
</SCRIPT>
</BODY>
</HTML>
|