mardi 1 octobre 2019

How to add the ELSE part [duplicate]

This question already has an answer here:

Every time I add the Else portion of the getHoroscope function it is ran multiple times along with the if part. I understand its because the if statement looping through but how can I make the else part only run once if the name of the horoscope is not entered correctly. such as n alert that says ("sorry you must have mispelled something or you did not enter a valid horoscope"); Everything else works fine, just cant seem to add an else portion without it running multiple times

    for(var i=0; i < horoscopes.length; i++) {
        if(input.value == horoscopes[i].name) {
            img.src = horoscopes[i].img;
            newH1.textContent = horoscopes[i].name;
            description.innerHTML = horoscopes[i].description;
            input.value = '';
            /***** IMAGE STYLE *****/
            img.style.height = '260px';
            description.style.margin = '46px 20px 100px 20px';
        } 
    }

};

Aucun commentaire:

Enregistrer un commentaire