Advertisement
gskorchev

old books

Feb 4th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function oldBooks(input) {
  2.     let nameOfBook = input.shift();
  3.     let numbersOfBooks = Number(input.shift());
  4.     let counter = 0;
  5.     while (counter <= numbersOfBooks) {
  6.         let searchingBook = input.shift();
  7.         if (searchingBook == nameOfBook) {
  8.             console.log(`You checked ${counter} books and found it.`);
  9.             break;
  10.         }
  11.         counter++;
  12.         if (searchingBook != nameOfBook && counter == numbersOfBooks) {
  13.             console.log(`The book you search is not here!`);
  14.             console.log(`You checked ${numbersOfBooks} books.`);
  15.  
  16.         }
  17.     }
  18. }
  19.  
  20. oldBooks(["Troy", 8, "Stronger", "Life style", "Troy"]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement