dimanche 8 novembre 2020

Why can't I use Regex to evaluate if...else statement [duplicate]

I'm trying to use regex to evaluate whether the newArray at index 0 is equivalent to the value stored in vowel. I know that this method doesn't work but I don't understand why. BTW I've just started learning how to code so I only really know Vanilla JS

function translate(val) {
    let newArray = Array.from(val)
    let vowel = /^[aeiouy]/gi
    let consonant = /[^aeiouy]/
    if (newArray[0] == vowel) {
        return 'vowel';
    } else if (newArray[0] == consonant) {
        return 'consonant'
    } {
        return 'none';
    }
}
 translate('inglewood')

Aucun commentaire:

Enregistrer un commentaire