JavaScript Vowel Counter: Problem-Solving with Pseudo Code

🧠 Thinking in Code: My JavaScript Problem-Solving Snapshot Today, I spent time focusing on how I think while coding, not just what I code. I chose a simple yet powerful JavaScript problem: 👉 Counting the number of vowels in a sentence Why this problem? Because it combines loops, condition checks, and clean logic, which are core fundamentals for any frontend or JavaScript developer. ✏️ Pseudo Code (Before Writing Any JS) Before touching the keyboard, I broke the logic down in plain English: Convert the sentence to lowercase Loop through each character Check if the character is a vowel Increase a counter when a vowel is found Writing this first made the actual coding much smoother. 💻 JavaScript Code function countVowels(str) { let count = 0; let vowels = "aeiou"; for (let i = 0; i < str.length; i++) { if (vowels.includes(str[i])) { count++; } } return count; } // Test cases console.log(countVowels("Hello World")); // 3 console.log(countVowels("JavaScript")); // 3 console.log(countVowels("AEIOU")); // ❌ Initially returned 0 🐞 What Went Wrong & How I Fixed It My function failed for uppercase vowels. Using console.log(), I quickly realized the comparison was case-sensitive. ✅ Fix applied: str = str.toLowerCase(); After adding this line, all test cases worked as expected. 💡 Key Takeaway (Aha Moment) This small exercise reminded me that: Good logic starts before writing code. Pseudo code + console.log() = faster debugging and clearer thinking. Even simple problems can teach big lessons about structure, clarity, and mindset. 📣 Let’s Learn Together How do you approach JavaScript problems? Do you write pseudo code first, or dive straight into coding? Would love to hear your process 👇 AlmaBetter #AlmaBetter #JavaScript #Debugging #ProblemSolving #FrontendBasics #CodeThinking #ISTJourney #LearningInPublic

To view or add a comment, sign in

Explore content categories