Daily Coding Challenge - Vowel Balance

Tell us what’s happening:

I  don't   understand   what happened  in the code

Your code so far

function isBalanced(s) {
let word =s.toLowerCase();
let str=word.length/2
let mid =Math.floor(str);
let count1=0;
let count2=0;
// for first half
for(let i=0 ; i<mid ; i++){
if(s[i]==="a"&& s[i]==="e"&& s[i]==="i"&& s[i]==="o"&& s[i]==="u"){
  count1=count1+1
}
}
//for second half
for (let i=mid +1 ; i<mid ;i++){
 if(s[i]==="a"&& s[i]==="e"&& s[i]==="i"&& s[i]==="o"&& s[i]==="u"){
   count2=count2+1
 }
}
if(count1===count2){
  return true;
}else{
  return false;
}
  
}
console.log( isBalanced("racecar"))

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36 Edg/144.0.0.0

Challenge Information:

Daily Coding Challenge - Vowel Balance
https://www.freecodecamp.org/learn/daily-coding-challenge/2025-08-11

Is it possible for s[i] to be a and e and i and o and u?

Will this ever run?

so which condition should I use please tell me

1 Like

the second half condition gone wrong

Can you describe in words what you want this condition to check for?

1 Like

I believe @gadeprathmesh12 is trying to count the number of vowels in two separate sections of a word. For example if the number of vowels in a eight letter word is four; are two vowels coming from the first four letters and the other two coming the last four letters of the word or does one section have more vowels than the other. Returning false if the latter is true.

You should use OR “||” instead of AND “&&“ when checking for the equality of s[i] in the if(). If the s[i] is forced to be all vowels at once the vowel count will incorrect and won’t increase.

I know what they are trying to do, but they need to be able to explain it in words themselves before they can implement the code.

You are simply providing the answer rather than helping them find it themselves.

It is great that you solved the challenge, but it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge. How to Help Someone with Their Code Using the Socratic Method