Advertisement
AlexandrP

01. Old Books

Dec 2nd, 2022
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function library(input) {
  2.  
  3.     let index = 1
  4.     let neededBook = input[0]
  5.     let book = 0
  6.     let checkedBooks = 0
  7.  
  8.     while (book !== "No More Books") {
  9.  
  10.         book = input[index]
  11.  
  12.         if (book == neededBook) {
  13.  
  14.             console.log(`You checked ${index-2} books and found it.`);
  15.  
  16.             break;
  17.         }
  18.  
  19.  
  20.         checkedBooks++
  21.  
  22.         index++
  23.  
  24.     }
  25.  
  26.     console.log(`The book you search is not here!`);
  27.     console.log(`You checked ${index-2} books.`);
  28.  
  29.  
  30.  
  31. }
  32.  
  33. library (["Bourne",
  34.  
  35. "True Story",
  36.  
  37. "Forever",
  38.  
  39. "More Space",
  40.  
  41. "The Girl",
  42.  
  43. "Spaceship",
  44.  
  45. "Strongest",
  46.  
  47. "Profit",
  48.  
  49. "Tripple",
  50.  
  51. "Stella",
  52.  
  53. "The Matrix",
  54.  
  55. "Bourne"])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement