Advertisement
Liliana797979

books

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