Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
5.8 kB
1
Indexable
Never
function book(author, title, description) {
    this.author = author;
    this.title = title;
    this.description = description;
    this.checkAuthor = function(authorName) {
        return this.author.toLowerCase() == authorName.toLowerCase();
    };
    this.checkTitle = function(titleName) {
        return this.title.toLowerCase() == titleName.toLowerCase();
    };
}

var b1 = new book("Thomas Mann", "Death in Venice", "One of the most famous literary works of the twentieth century, this novella embodies themes that preoccupied Thomas Mann in much of his work: the duality of art and life, the presence of death and disintegration in the midst of existence, the connection between love and suffering and the conflict between the artist and his inner self."); 
var b2 = new book("James Joyce", "A portrait of the artist as a young man", "This book is a fictional re-creation of the Irish writer's own life and early environment. The experiences of the novel's young hero, unfold in astonishingly vivid scenes that seem freshly recalled from life and provide a powerful portrait of the coming of age of a young man of unusual intelligence, sensitivity and character.");
var b3 = new book("E. M. Forster", "A room with a view", "This work displays an unusually perceptive view of British society in the early 20th century.It is a social comedy set in Florence, Italy, and Surrey, England. Its heroine, Lucy Honeychurch, struggling against straitlaced Victorian attitudes of arrogance, narroe mindedness and sobbery, falls in love - while on holiday in Italy - with the socially unsuitable George Emerson.");
var b4 = new book("Isabel Allende", "The house of spirits", "Allende describes the life of three generations of a prominent family in Chile and skillfully combines with this all the main historical events of the time, up until Pinochet's dictatorship.");
var b5 = new book("Isabel Tallende", "Of shadows", "The whole world of Irene Beltran, a young reporter in Chile at the time of the dictatorship, is destroyed when she discovers a series of killings carried out by government soldiers. With the help of a photographer, Francisco Leal, and risking her life, she tries to come up with evidence against the dictatorship.");
/*
var books2D = [
    ["Thomas Mann", "Death in Venice", "One of the most famous literary works of the twentieth century, this novella embodies themes that preoccupied Thomas Mann in much of his work: the duality of art and life, the presence of death and disintegration in the midst of existence, the connection between love and suffering and the conflict between the artist and his inner self."],
    ["James Joyce", "A portrait of the artist as a young man", "This book is a fictional re-creation of the Irish writer's own life and early environment. The experiences of the novel's young hero, unfold in astonishingly vivid scenes that seem freshly recalled from life and provide a powerful portrait of the coming of age of a young man of unusual intelligence, sensitivity and character."],
    ["E. M. Forster", "A room with a view", "This work displays an unusually perceptive view of British society in the early 20th century.It is a social comedy set in Florence, Italy, and Surrey, England. Its heroine, Lucy Honeychurch, struggling against straitlaced Victorian attitudes of arrogance, narroe mindedness and sobbery, falls in love - while on holiday in Italy - with the socially unsuitable George Emerson."],
    ["Isabel Allende", "The house of spirits", "Allende describes the life of three generations of a prominent family in Chile and skillfully combines with this all the main historical events of the time, up until Pinochet's dictatorship."],
    ["Isabel Tallende", "Of shadows", "The whole world of Irene Beltran, a young reporter in Chile at the time of the dictatorship, is destroyed when she discovers a series of killings carried out by government soldiers. With the help of a photographer, Francisco Leal, and risking her life, she tries to come up with evidence against the dictatorship."],
];

for(var i = 0; i < books2D.length; i++){
    if(myAuthor.value == books2D[i][0])
}*/

var books = [b1, b2, b3, b4, b5];
var byAuthor = false;
var myAuthor = document.getElementById("author");
var myTitle = document.getElementById("title");
var myDescription = document.getElementById("description");

function findBook(){
    if(byAuthor == true){
        var found = false;
        for(var i = 0; i < books.length; i++){
            if(books[i].checkAuthor(myAuthor.value)){
                myTitle.value = books[i].title;
                myDescription.innerHTML = books[i].description;
                return;
            }
        }
        if(found == false){
            myTitle.value = "";
            myDescription.innerHTML = "Book Not Found";
            return;
        }
    }
    else{
        for(var i = 0; i < books.length; i++){
            if(books[i].checkTitle(myTitle.value)){
                myAuthor.value = books[i].author;
                myDescription.innerHTML = books[i].description;
                return;
            }
        }
        if(found == false){
            myTitle.value = "";
            myDescription.innerHTML = "Book Not Found";
            return;
        }
    }

}

function findByAuthor(){
    byAuthor = true;
}
function findByTitle(){
    byAuthor = false;
}

function clearInfo(){
    myAuthor.value = "";
    myTitle.value = "";
    myDescription.innerHTML = "";
}

myTitle.addEventListener("input", findByTitle);
myAuthor.addEventListener("input", findByAuthor);
document.getElementById("find").addEventListener("click", findBook);
document.getElementById("clear").addEventListener("click", clearInfo);