when I trigger the if condition, why the else will print out as well? someone could indicate what's the problem of the code below? written in JS.
const rainbow = ['red', 'orange', 'yellow', 'green', 'cyan', 'blue', 'violet'];
let colour = prompt("What is your favourite colour?").toLowerCase();
for (let i = 0; i < rainbow.length; i+=1) {
if (rainbow[i] === colour) {
console.log("yes")
}
else {
console.log(rainbow.join(" *** "));
}
}
Aucun commentaire:
Enregistrer un commentaire