ProdanTenev

Old Books

Mar 1st, 2022
1,058
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 0.73 KB | None | 0 0
  1. function oldBooks(input) {
  2.     let index = 0;
  3.     let searchedBook = input[index];
  4.     index++;
  5.     let bookCounter = 0;
  6.     let isNotHere = false;
  7.     while (true) {
  8.         let currentBook = input[index];
  9.         index++;
  10.         bookCounter += 1;
  11.         if (currentBook === searchedBook) {
  12.         bookCounter -= 1;
  13.             console.log(`You checked ${bookCounter} books and found it.`);
  14.             break;
  15.         }
  16.         if (currentBook === "No More Books") {
  17.             isNotHere = true;
  18.         if (isNotHere) {
  19.             bookCounter -= 1;
  20.             console.log("The book you search is not here!");
  21.             console.log(`You checked ${bookCounter} books.`);
  22.             break;
  23.         }
  24.         }
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment