Skip to content

Instantly share code, notes, and snippets.

@mojaray2k
Last active August 25, 2018 07:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mojaray2k/d4921fb076ac1daa07c44cbe8e764275 to your computer and use it in GitHub Desktop.
Save mojaray2k/d4921fb076ac1daa07c44cbe8e764275 to your computer and use it in GitHub Desktop.
JS Bin// source http://jsbin.com/diqumox
// Count the number of vowels in a string using just var
function count(targetString){
var characters = ['a', 'e', 'i', 'o', 'u'];
var number = 0;
for (var i = 0; i< targetString.length; i++){
if(characters.includes(targetString[i])){
number++
}
}
return number;
}
console.log(count('aeiobzxceiaipbiox'));
// Count the number of vowels in a string using const and let
function count(targetString){
const characters = ['a', 'e', 'i', 'o', 'u'];
let number = 0;
for (var i = 0; i< targetString.length; i++){
if(characters.includes(targetString[i])){
number++
}
}
return number;
}
console.log(count('aeiobzxceiaipbiox'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment