Created
September 3, 2017 17:45
-
-
Save jochri3/aa40c9670480d7c5689fa888edd087c4 to your computer and use it in GitHub Desktop.
null created by ChrisLis - https://repl.it/HaK8/30
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Write a function that takes a string and returns the number of vowels | |
// in the string. You may assume that all the letters are lower cased. | |
// You can treat "y" as a consonant. | |
// | |
// Difficulty: easy. | |
function count_vowels(string) | |
{ | |
var nbr_voyelles=0; | |
var list_voyelles="aeiouyAEIOUY" | |
for(var i=0;i<string.length;i++) | |
{ | |
if(list_voyelles.includes(string[i])) | |
{ | |
nbr_voyelles +=1 | |
} | |
} | |
return nbr_voyelles | |
} | |
console.log(count_vowels("abdc")) | |
// These are tests to check that your code is working. After writing | |
// your solution, they should all print true. | |
console.log("\nTests for //count_vowels") | |
console.log("===============================================") | |
console.log('count_vowels("abcd") == 1: ' + (count_vowels('abcd') == 1)) | |
console.log('count_vowels("color") == 2: ' + (count_vowels('color') == 2)) | |
console.log('count_vowels("colour") == 3: ' + (count_vowels('colour') == 3)) | |
console.log('count_vowels("cecilia") == 4: ' + (count_vowels('cecilia') == 4)) | |
console.log("===============================================") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment