Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function bookcheck(input) {
- let book = input[0];
- let count = Number(input[1]);
- let i = 2;
- while (book !== input[i]) {
- i++;
- if (book == input[i]) {
- let checked = i - 2;
- console.log(`You checked ${checked} books and found it.`);
- break;
- } else if (i == count) {
- console.log(`The book you search is not here!\nYou checked ${count} books.`);
- break;
- }
- }
- }
- //test1// bookcheck([
- // 'Troy',
- // '8',
- // 'Stronger',
- // 'Life Style',
- // 'Troy'
- // ]);
- //test2// bookcheck([
- // 'The Spot',
- // '4',
- // 'Hunger Games',
- // 'Harry Potter',
- // 'Torronto',
- // 'Spotify'
- // ]);
- //test 3// bookcheck([
- // 'Bourne',
- // '32',
- // 'True Story',
- // 'Forever',
- // 'More Space',
- // 'The Girl',
- // 'Spaceship',
- // 'Strongest',
- // 'Profit',
- // 'Tripple',
- // 'Stella',
- // 'The Matrix',
- // 'Bourne'
- // ]);
Add Comment
Please, Sign In to add comment