Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function oldBooks(input) {
- let nameOfBook = input.shift();
- let numbersOfBooks = Number(input.shift());
- let counter = 0;
- while (counter <= numbersOfBooks) {
- let searchingBook = input.shift();
- if (searchingBook == nameOfBook) {
- console.log(`You checked ${counter} books and found it.`);
- break;
- }
- counter++;
- if (searchingBook != nameOfBook && counter == numbersOfBooks) {
- console.log(`The book you search is not here!`);
- console.log(`You checked ${numbersOfBooks} books.`);
- }
- }
- }
- oldBooks(["Troy", 8, "Stronger", "Life style", "Troy"]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement