12
I was trying to create a code with Javascript that after reading the letter entered showed if it was a vowel or consonant but with any letter I put the code answers me that and a consonant even if it is a vowel.
I can’t find the error in the code.
var valorlido
function lerletra() {
valorlido = prompt("Introduza uma letra")
return valorlido
}
function isvogal(caracter) {
switch (caracter) {
case "a":
case "A":
case "e":
case "E":
case "i":
case "I":
case "o":
case "O":
case "u":
case "U":
break
return true
default:
return false
}
}
var letra
lerletra ();
if (isvogal(letra) == true) {
alert("A letra é Vogal")
} else {
alert("A letra é consoante")
}
Take the break is leaving the switch without returning
– novic
puts break after Return
– CypherPotato