Question: I am trying to use a method to return the value of the index of an array so I can use it in another class, but I can't seem to make it work. Here is my code:

This one tells me there is no return statement.

```
public int getCourseIndex(String course){
    for (int i = 0; i<courses.length; i++)
       if(course.equals(courses[i])) 
}

```

I also tried and I think it just returns 0:

```
public int getCourseIndex(String course){
    int total = 0;
    for (int i = 0; i<courses.length; i++){
        if(course.equals(courses[i])){
            total++;
    }

    return total;
}

```

Answer: 
You need to go through the array with a for loop and if you find what you were looking for, return the current loop variable value (in the following code the `i` value), which actually represents the index in the array on which it was found.

If the loop ends and nothing gets returned, it means that what you were looking for wasn't in the array. Then you should return something to inform you about that fact. It needs to be something that can't get returned from inside the for loop, which are negative numbers (typically a -1). 

```
public int getCourseIndex(String course){
    for (int i = 0; i<courses.length; i++){
        if(course.equals(courses[i])){
            return i;
        }
    }
    return -1; // not found
}

```
To return the index you should traverse the loop and return the `i` when your validation results `true`.

If not found you have two option, return `-1` or throw an exception. 

```
public int getCourseIndex(String course){

 for (int i = 0; i < courses.length; i++){
   if(course.equals(courses[i])){
    return i;
   }
 }
 return -1;
}

```