Advertisement
Spocoman

Old Books

Oct 13th, 2023 (edited)
733
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function oldBooks(input) {
  2.     let book = input[0];
  3.     let bookCount = Number(input[1]);
  4.     let counter = 0, index = 2;
  5.     let command = input[index++];
  6.  
  7.     for (let i = 0; i < bookCount && command != ""; i++) {
  8.         if (command == "No More Books" || command == book) {
  9.             if (command == book) {
  10.                 console.log(`You checked ${counter} books and found it.`);
  11.             } else {
  12.                 console.log(`The book you search is not here!\nYou checked ${counter} books.`);
  13.             }
  14.             return;
  15.         }
  16.         command = input[index++];
  17.         counter++;
  18.     }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement