//////////////////////////////////////////////////////////////////////////////

<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript">
// 3 constructor functions of Person, Book, and Library
function Person(fname,lname)
{
    this.firstName = fname;
    this.lastName = lname;
}

function Book(booktitle,pages,price)
{
    this.bookTitle = booktitle;
    this.pages = pages;
    this.price = price;
    this.authors = new Array(arguments.length-3);
    for(i=0;i<arguments.length-3;i++)
    {
     this.authors[i] = arguments[i+3];
    }
}

function Library()
{
    this.books = new Array(arguments.length);
    for(i=0;i<arguments.length;i++)
    { 
     this.books[i] = arguments[i];
    }
    this.totalPrice = function(){
    var totalCost = 0;
    for(i=0;i<this.books.length;i++)
    {
   totalCost += this.books[i].price;
    }
    return totalCost;
    }
    this.averagePrice = new Function("return this.totalPrice()/this.books.length");
    var flag;
    this.getBook = function(name){
        for(i=0;i<this.books.length;i++)
    {
        if(this.books[i].bookTitle == name )
        {
         this.flag = i;
        }
    }


    }

    this.getAuthors = function(){
   var toSay = "";

     for(j=0;j<this.books[this.flag].authors.length;j++){
       var authName = 
       this.books[this.flag].authors[j].lastName + " " + 
       this.books[this.flag].authors[j].firstName + "\t";
       if(toSay.indexOf(authName)!=-1)
       continue;
       toSay+=""+authName;
     }

 return toSay;
 }
}


var john = new Person("Smith", "John");
var jack = new Person("Simpson", "Jack");
var bobby = new Person("Franklin", "Bobby");
var albert = new Person("Camus", "Albert");
var java = new Book("Dummy Java", 1000, 29.95, john, jack);
var php = new Book("Dummy PHP", 300, 19.95, john);
var xml = new Book("Dummy XML", 150, 9.95, bobby, albert);
var js = new Book("Dummy JavaScript", 2000, 49.95, albert);
var lib = new Library(java, php, xml, js);
alert(lib.totalPrice()); // output 109.8
alert(lib.averagePrice()); // output 27.45
lib.getBook("Dummy XML");
alert(lib.getAuthors()); // output John Smith, Jack Simpson
</script>
</head>
<body>
</body>
</html>



/////////////////////////////////////////////////////////////////////

Instead of using the below two statements

lib.getBook("Dummy XML");
alert(lib.getAuthors()); // output John Smith, Jack Simpson

it works fine to produce the above output. but i want to produce the abouve output using nested methods.

i want to use a single statement alert(lib.getBook("Dummy XML").getAuthors()); to produce the same output ( // output John Smith, Jack Simpson)

Please help me on how to call a method in a method.

Thanks

at the end of the getBook method try adding return this;

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.