01.Old Books JavaScript JS
здравейте, имам проблем със задачата Old books от while циклите.
https://pastebin.com/5ay8Tnra
здравейте, имам проблем със задачата Old books от while циклите.
https://pastebin.com/5ay8Tnra
Здравейте, поправих малко кода и сега е 100/100. Имахте грешка в условието за повторение(counter < numberofBooks, а всъщност е counter !=numberofBooks ), както и 2 пъти бяхте въвели да се подава търсената книга(един път на ред 8 и един път на ред 11. На ред 11 е излишно)
function library(input) {
    let favoriteBook = input.shift();
    let numberofBooks = Number(input.shift());
   
    let counter = 0;
    let bookisFound = false;
 
    let nextBookName = input.shift();
   
    while (counter !=numberofBooks) {
       
 
        if(nextBookName == favoriteBook){
            bookisFound  = true;
            break;
        }
        counter++;
        nextBookName = input.shift();
        }
    if(bookisFound ==  false){
            console.log(`The book you search is not here!`);
            console.log(`You checked ${numberofBooks} books.`);
    }else{
            console.log(`You checked ${counter} books and found it.`);
    }
    }
здрасти, ето и още едно решение:
function oldBooks(input) {
let theBook = input.shift();
let checksNumber = Number(input.shift());
let nextCheck = input.shift();
let counter = 0;
while (counter < checksNumber) {
if (nextCheck === theBook) {
console.log(`You checked ${counter} books and found it.`);
break;
} else {
nextCheck = input.shift();
}
counter++;
} if (counter >= checksNumber) {
console.log(`The book you search is not here!`);
console.log(`You checked ${counter} books.`);
}
}