Advertisement
vikkktor

oldBooks

Jun 6th, 2021 (edited)
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function oldBooks(input) {
  2.     let index = 0;
  3.     let favoriteBook = input[0];
  4.     index++;
  5.  
  6.     let command = input[index];
  7.     index++;
  8.     let counter = 0;
  9.  
  10.     let isFound = false;
  11.  
  12.     while (command !== "No More Books") {
  13.         let book = command;
  14.         if (favoriteBook === book) {
  15.             console.log(`You checked ${counter} books and found it.`);
  16.             isFound = true;
  17.             break;
  18.         }
  19.         counter++;
  20.         command = input[index];
  21.         index++;
  22.     }
  23.  
  24.     if (!isFound) {
  25.         console.log(`The book you search is not here!`);
  26.         console.log(`You checked ${counter} books.`);
  27.     }
  28. }
  29.  
  30.  
  31. oldBooks(["The Spot",
  32.     "Hunger Games",
  33.     "Harry Potter",
  34.     "Torronto",
  35.     "Spotify",
  36.     "No More Books"])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement