Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function oldBooks(input) {
- let index = 0;
- let searchedBook = input[index];
- index++;
- let bookCounter = 0;
- let isNotHere = false;
- while (true) {
- let currentBook = input[index];
- index++;
- bookCounter += 1;
- if (currentBook === searchedBook) {
- bookCounter -= 1;
- console.log(`You checked ${bookCounter} books and found it.`);
- break;
- }
- if (currentBook === "No More Books") {
- isNotHere = true;
- if (isNotHere) {
- bookCounter -= 1;
- console.log("The book you search is not here!");
- console.log(`You checked ${bookCounter} books.`);
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment