thUBat wUBay (array)

add 'UB' before every vowel

by trentHarlem

HTML

<h1>
  thUBat wUBay
</h1>
<label for='userInput'>Type Here:</label>
<input id='userInput' type='text'/>
<br><br>
<button id='button' type='submit'>
 then Click Here
</button>
<p id='display'>
</p>

CSS

body {
  font: 1.1em system-ui;
}

JavaScript

const display = document.getElementById('display')
const userInput = document.getElementById('userInput')
const button = document.getElementById('button')

const work = (str) => {
  const vowels = ['a', 'e', 'i', 'o', 'u'];
  // console.log(str);
  //console.log(vowels);
  const strSplit = str.split('');
  //console.log(strSplit);
  strSplit.forEach((char, i) => {
    if (vowels.includes(char) && char !== strSplit[0]) {
      //let start = strSplit.indexOf(char)
      strSplit.splice(i, 0, 'U', 'B')
      return strSplit.join('');
    }
  })
  return strSplit.join('');
}

function ubub(str) {
  str = userInput.value || str
  userInput.value = ''
  // const vowels = ['a', 'e', 'i', 'o', 'u'];
  const arr = str.split(' ');
  display.innerHTML = arr.map(word => work(word)).join(' ');
  console.log(arr.map(word => work(word)).join(' '));
  return arr.map(word => work(word)).join(' ')
}
//ubub('that way')
//ubub('van halen')
button.addEventListener('click', ubub);