Didart

Old Books

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