使用if else语句,用户输入的字符是元音或辅音

character entered by a user is a vowel or consonant, using if else statement

本文关键字:字符 输入 else if 语句 用户 使用      更新时间:2023-09-26

请建议代码有什么问题??

<script>
var chrctr = prompt("Enter a character");
    if (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u') {
        document.write("Is a Vowel");
    }
    else {
    document.write ("Is a consonant");
    }
</script>

您的变量名称是chrctr,所以您应该检查chrctr而不是a

<script>
var chrctr = prompt("Enter a character");
    if (chrctr == 'a' || chrctr == 'e' || chrctr == 'i' || chrctr == 'o' || chrctr == 'u') {
        document.write("Is a Vowel");
    }
    else {
    document.write ("Is a consonant");
    }
</script>