TZinovieva

Old Books 100/100

Oct 13th, 2022
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function oldBooks(input) {
  2.     let favouriteBook = input[0];
  3.  
  4.     let index = 1;
  5.     let bookName = input[index];
  6.     index++;
  7.  
  8.     let checkedBooks = 0;
  9.     let isFound = false;
  10.     while (bookName !== "No More Books") {
  11.  
  12.         if (bookName === favouriteBook) {
  13.         isFound = true;
  14.         console.log(`You checked ${checkedBooks} books and found it.`);
  15.         return;
  16.         }
  17.         checkedBooks++;
  18.         bookName = input[index];
  19.         index++;
  20.        
  21.     }
  22.         console.log(`The book you search is not here!`);
  23.         console.log(`You checked ${checkedBooks} books.`);
  24.     }
Advertisement
Add Comment
Please, Sign In to add comment