Here's the task - I have an input field where I can enter a text and I would like to replace the occurrence of Vowels with numbers eg (A,E,I,O,U - 1,2,3,4,5) and add 'a' to all the other consonants eg - The input field takes in 'Victor as an input and what is printed on the page is 'Va3cata4ra'.

So far, i've been able to get the consonants to display an 'a' at the end of it using template literals and passing the variable to a setState. However I'm having issues getting the Vowels to show their numerical values as explained above. I've tried Switch , if else, for some reason, none is working

export default class App extends Component {

state = {
mytext: ''

onChangeHandler = (event) => {
    const newText =;
    const splitText = newText.split('');
    let tempArr = []

    for (let onye in splitText) {
        else if (onye === 'e') {
        } else if (onye === 'i') {
        } else if (onye === 'o') {
        } else if (onye === 'u') {
        } else {
            return onye

        //This got the consonants to display a after each one

        const raCon = `${splitText[onye]}a`

        mytext: tempArr

Expected result would have 'a' at the end of each consonant and numerical values for every vowel corresponding with (A,E,I,O,U)- (1,2,3,4,5)

Re: How can I replace the occurrence of a letter within a string with a number 80 80

Why the parseInts? Don't you just want to insert the character that represents 1,2,3 etc?

And why the === (identity test) rather than a simple == (equals)?

Re: How can I replace the occurrence of a letter within a string with a number 80 80

Can someone please tag this thread with the appropriate programming language?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.