Getting ‘Script error’ and can’t find why

I'm practicing a little bit in DartPad some problems and can't get the solution, the code below is what I think is OK, but I'm getting 'Script error' in the console.

The problem that I'm solving is that I need to make function that has two arguments, first one in some random sentence and second is any character, and I need to find how many characters are in that sentence.

Please respond with the error that I don't see or just give me solution. Ty

void main() {
  numberOfSameCharacters(randomString: 'Today is a nice day.', character: 'a');
}

void numberOfSameCharacters({String randomString, String character}) {
  int sameCharacters = 0;

  List<String> randomStringList = randomString.split('');

  for (int i = 0; i <= randomStringList.length; i++) {
    if (character.toLowerCase() == randomStringList[i].toLowerCase()) {
      sameCharacters += 1;
    }
  }

  print(sameCharacters);
}


Read more here: https://stackoverflow.com/questions/64899086/getting-script-error-and-cant-find-why

Content Attribution

This content was originally published by Stefan Lukovic at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: