vborislavova

01. Old Books - while - loops - ex

Mar 4th, 2020
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function oldBooks(input) {
  2.     let book = input.shift();
  3.     let libraryCapacity = Number(input.shift());
  4.    
  5.     let checkedBooks = 0;
  6.     let isFound = false;
  7.  
  8.     while(checkedBooks <= libraryCapacity) {
  9.         let currentBook = input.shift();
  10.        
  11.         if(currentBook === book) {
  12.             console.log(`You checked ${checkedBooks} books and found it.`);
  13.             isFound = true;
  14.             break;
  15.         }
  16.  
  17.         checkedBooks ++;
  18.     }
  19.  
  20.     if(isFound === false){
  21.     console.log("The book you search is not here!");
  22.     console.log(`You checked ${libraryCapacity} books.`);
  23.     }
  24. }
Add Comment
Please, Sign In to add comment