<html>
<head><title></title>
</head>
<body>
<script language="javascript">
do
{ var title;
var close;
//object for prompting the user to enter data
function books(title, author, category, value)
{
this.title = title;
this.author = author;
this.category = category;
this.value = value;
}
books.prototype.addBook = function()
{
this.title = prompt("Enter the title of the book","Title");
this.author = prompt("Enter the author of the book","Author");
this.category = prompt("Enter the category for the book","Category");
this.value = prompt("Enter a value for this book","Value");
}
books.prototype.showTitle = function ()
{
return this.title;
}
books.prototype.showAuthor = function ()
{
return this.author;
}
books.prototype.showValue = function ()
{
return this.value;
}
books.prototype.showCategory = function ()
{
return this.category;
}
//array for adding the books & display all books
function NumBooks()
{
this.bookList = new Array(2);
}
NumBooks.prototype.addBook = function()
{
for (var i=0;i<this.bookList.length;i++)
{
this.bookList = new books();
this.bookList.addBook();
}
}
NumBooks.prototype.showBooks = function()
{
for (var i=0; i<this.bookList.length; i++)
{
document.write(this.bookList.showTitle()+"<br>");
document.write(this.bookList.showAuthor()+"<br>");
document.write(this.bookList.showValue()+"<br>");
document.write(this.bookList.showCategory()+"<br><br>");
}
}
NumBooks.prototype.searchTitle = function(title)
{
var i=0;
while (i< this.bookList.length && title != this.bookList.showTitle())
{i++}
if ( i == this.bookList.length )
{
document.write(" Book Not Found ");
}
else
{
document.write(" Book Found ");
}
}
NumBooks.prototype.searchAuthor = function(author)
{
var i=0;
while (i< this.bookList.length && author != this.bookList.showAuthor())
{i++}
if ( i == this.bookList.length )
{
document.write(" Book Not Found ");
}
else
{
document.write(" Book Found ");
}
}
//SELECTION FUNCTION
function selection()
{
var choice = prompt("Would you like to search by - Author/Title","Title")
switch (choice)
{
case "Author": test.searchAuthor(prompt("Name of Author to search?","Author"));
break;
case "Title": test.searchTitle(prompt("Name of Title to seach?","Title"));
break;
default: document.write("Sorry, Try again");
}
}
var test = new NumBooks()
test.addBook();
test.showBooks();
selection();
close = (prompt("Would you like to close it - y/n?"));
}
while (close != "y");
</script>
</body>
</html>
вопрос по JavaScript
хочу задать пару вопрос по ЖаваСкрипту. мне дали задание сделать програмку для "библиотеки". не такая уж вроди и сложная задачка, но я так и не могу сделать так, что бы она обновляла "цену (value)" на книжку. а потом что бы всё складывала и давала сложенную сумму. помогите плиз!
CODE:
Код: