Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function oldBooks(input) {
- let favouriteBook = input[0];
- let index = 1;
- let bookName = input[index];
- index++;
- let checkedBooks = 0;
- let isFound = false;
- while (bookName !== "No More Books") {
- if (bookName === favouriteBook) {
- isFound = true;
- console.log(`You checked ${checkedBooks} books and found it.`);
- return;
- }
- checkedBooks++;
- bookName = input[index];
- index++;
- }
- console.log(`The book you search is not here!`);
- console.log(`You checked ${checkedBooks} books.`);
- }
Advertisement
Add Comment
Please, Sign In to add comment