mercredi 25 septembre 2019

In JavaScript, is there any way of using an else statement without having used an initial if-statement?

I'm trying to use an else-statement with a ternary operator. This is because for my code to use an if-statement, it would make it a very long one. Is there any way to pull of a ternary operator-else statement combination?

This is for a JS code. I have tried it before but the code was a long one. So I'm not sure whether it would run.

    for(let i=1;i<10;i++){
    (i%2 === 0)?console.log("Yup"):console.log("Nope");
    else{
    console.log(i);
    }
    }

Aucun commentaire:

Enregistrer un commentaire