Advertisement
Mitfreex

OLD BOOKS 100/100

May 23rd, 2020
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function bookcheck(input) {
  2.  
  3.     let i = 0;
  4.     let data = input;
  5.     let book = data[i];
  6.     i++;
  7.     let count = Number(data[i]);
  8.     i++;
  9.  
  10.     while ((book !== data[i]) && ((i-2) <= count)) {
  11.         i++;
  12.      
  13.         }
  14.  
  15.    
  16.  
  17.     if (book == data[i]) {
  18.  
  19.         console.log(`You checked ${i-2} books and found it.`);
  20.         }
  21.        
  22.         else {
  23.         console.log(`The book you search is not here!`);
  24.         console.log(`You checked ${count} books.`);
  25.        
  26.  
  27. }
  28.  
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement