Help with functions

Hello,
I am trying to make a function that returns the string str in all lowercase. The console is saying that
String allLowercase (String str) must return a result of type string. I’m stumped and obviously a little lost, can anyone point me in the right direction?

void setup () {
 String str = "ABCD 123, Fall 2019, Pizza";
 String lowerStr = allLowercase (str);
 println(lowerStr);

}

 String allLowercase (String str) {
  String res="";
  char c;
  
  for (int i = 0; i < str.length();++i){
    c = str.charAt(i);
    if (c >= 'A' && c <= 'Z'){
      c=(char)(c+32);
      res = res+c;
      return res;
    } else {
      return null;
    }
    
}

 }
1 Like

i think i see the same home work here last week,
did you use search here ( or google search ) already?

hope it helps: Calling a function for making a string lowercase without predefined function


possibly only the program flow,
while the rest looks good

void setup () {
  String str = "ABCD 123, Fall 2019, Pizza";
  println(str);
  String lowerStr = allLowercase(str);
  println(lowerStr);
}

String allLowercase(String str) {
  String res="";
  char c;
  for (int i = 0; i < str.length(); ++i) {
    c = str.charAt(i);
    if (c >= 'A' && c <= 'Z')  c=(char)(c+32);
    res = res+c;
  }
  return res;
}

1 Like