Mitfreex

01. Old Books (Exercises-17.05.2020)

May 23rd, 2020
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function bookcheck(input) {
  2.  
  3.     let book = input[0];
  4.     let count = Number(input[1]);
  5.     let i = 2;
  6.  
  7.     while (book !== input[i]) {
  8.         i++;
  9.         if (book == input[i]) {
  10.             let checked = i - 2;
  11.             console.log(`You checked ${checked} books and found it.`);
  12.             break;
  13.         } else if (i == count) {
  14.             console.log(`The book you search is not here!\nYou checked ${count} books.`);
  15.             break;
  16.         }
  17.     }
  18.  
  19.  
  20. }
  21.  
  22. //test1// bookcheck([
  23. //     'Troy',
  24. //     '8',
  25. //     'Stronger',
  26. //     'Life Style',
  27. //     'Troy'
  28. // ]);
  29.  
  30. //test2//  bookcheck([
  31. //     'The Spot',
  32. //     '4',
  33. //     'Hunger Games',
  34. //     'Harry Potter',
  35. //     'Torronto',
  36. //     'Spotify'
  37. //  ]);
  38.  
  39. //test 3// bookcheck([
  40. //     'Bourne',
  41. //     '32',
  42. //     'True Story',
  43. //     'Forever',
  44. //     'More Space',
  45. //     'The Girl',
  46. //     'Spaceship',
  47. //     'Strongest',
  48. //     'Profit',
  49. //     'Tripple',
  50. //     'Stella',
  51. //     'The Matrix',
  52. //     'Bourne'
  53. // ]);
Add Comment
Please, Sign In to add comment