Session 3
Take home excercise
Create a modest bit of code that takes an arbitrary string of characters and which prints the number of vowels and consonants that it finds in the string. A consonant is defined here as any non-vowel character, which means that characters such as β+β, β$β and β&β (for example) count as consonants even though such symbolic characters are not what we usually hold to be consonants. Note that your solution should consider upper-case and equivalent lower-case characters to be the same. That is, the following string βAcaDEβ has three vowels and two consonants.
const Str = 'HAllo ho##w# many vowels do i have';let Vowels = ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'];let consonentString = '';let vowelString = '';for (let Consonents of Str) { if (Vowels.indexOf(Consonents) === -1) { consonentString += Consonents; } else { vowelString += Consonents; }}console.log(consonentString);console.log('Consonents: ' + consonentString.length);console.log(vowelString);console.log('Vowels: ' + vowelString.length);Notes
I'm still gooogling to find a solution to things which is worrying me. The solution is almost immediately obvious to me when someone else writes it, but I would like to be able to arrive at the solution without googling. I feel like this is a big shortcoming if I come up against a problem I can't google my way out of.
I feel like my grasp of assignment operators isn't great. I don't think my grasp of iteration is great yet either even though this is one of the main aspects I've looked at so far.
I hadn't come across for..of statements like this one above for (let Consonents of Str) before. I need to look at this more in depth.
I thought loops were simple but it feels like they do extremely powerful things when you need them to.
I didn't understand that += would add the values of a string into another string. I would not have known that and didn't get it until I came across this after I had solved it.
I wonder how long i'll feel like an idiot for when it comes to programming. I feel like an idiot right up until the point I get something to work. Then I try my best to pick apart what I was doing wrong in the first place. This has happened when I was learning HTML + CSS, so i'm used to it. I think maybe js makes me feel like an even bigger idiot at the moment though :)
I would like to maybe try simpler tasks until I feel like i've 100% understood the concept.