syco__
07-17-2011, 03:54 AM
Another example from Sams Teach Your self JavaScript.
I have created the new object it prints the business cards out that are stored as you can see here.
function PrintCard() {
line1 = "<b>Name: </b>" + this.name + "<br>\n";
line2 = "<b>Address: </b>" + this.address + "<br>\n";
line3 = "<b>Work Phone: </b>" + this.workplace + "<br>\n";
line4 = "<b>Home Phone: </b>" + this.homephone + "<hr>\n";
document.write(line1,line2,line3,line4);
}
function Card(name,address,work,home) {
this.name = name;
this.address = address;
this.workplace = work;
this.homephone = home;
this.PrintCard = PrintCard;
}
// Create the objects.
sue = new Card ("Sue Suthers", "123 Elm Street", "555-1234", "555-9876");
chris = new Card ("Chris Suthers", "567 Rum Road", "555-4990", "555-8127");
james = new Card ("James Suthers", "17 Junk Court", "555-3334", "555-1596");
ken = new Card ("Ken Suthers", "1 Frank Circuit", "555-2365", "555-23659");
This is all good and i understand it. It is this the printing part i want to know if there is another way to print all 4 of them by naming them in a different way and looping through to print them i think i just answered my own question but it there a built in way to print all of the different cards? here is the current code.
//print Cards
sue.PrintCard();
chris.PrintCard();
james.PrintCard();
ken.PrintCard();
Thanks
I have created the new object it prints the business cards out that are stored as you can see here.
function PrintCard() {
line1 = "<b>Name: </b>" + this.name + "<br>\n";
line2 = "<b>Address: </b>" + this.address + "<br>\n";
line3 = "<b>Work Phone: </b>" + this.workplace + "<br>\n";
line4 = "<b>Home Phone: </b>" + this.homephone + "<hr>\n";
document.write(line1,line2,line3,line4);
}
function Card(name,address,work,home) {
this.name = name;
this.address = address;
this.workplace = work;
this.homephone = home;
this.PrintCard = PrintCard;
}
// Create the objects.
sue = new Card ("Sue Suthers", "123 Elm Street", "555-1234", "555-9876");
chris = new Card ("Chris Suthers", "567 Rum Road", "555-4990", "555-8127");
james = new Card ("James Suthers", "17 Junk Court", "555-3334", "555-1596");
ken = new Card ("Ken Suthers", "1 Frank Circuit", "555-2365", "555-23659");
This is all good and i understand it. It is this the printing part i want to know if there is another way to print all 4 of them by naming them in a different way and looping through to print them i think i just answered my own question but it there a built in way to print all of the different cards? here is the current code.
//print Cards
sue.PrintCard();
chris.PrintCard();
james.PrintCard();
ken.PrintCard();
Thanks