function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Deepika Reddy 16Deepika Reddy 16 

The following trailhead doesnt work for me can someone tell me error plz................

Deepika Reddy 16
The following code doesnt work for me.....

CODE:
public class StringArrayTest 
{
    public static list<string> generateStringArray(integer n)
    {
           list<string> t =new list<string>();
           for(integer i =0;i<n; i++)
           {
               t.add('Test'+ i);
               
            }
             return t;     
    }

}

ERROR:

Challenge Not yet complete... here's what's wrong: 
Executing the 'generateStringArray' method failed. Either the method does not exist, is not static, or does not return the proper number of strings.
 
Ajay K DubediAjay K Dubedi
Hi Deepika,
Use this code.
public class StringArrayTest{
    public static string[] generateStringArray(integer n){
          String[] myArray = new List<String>();
        for(Integer i=0;i<n;i++) {
                myArray.add('Test ' + i);
        }
     return myArray;   
    }     
    }
Regards,
Ajay
 
Amit Chaudhary 8Amit Chaudhary 8
You need to add Space In your string like below
t.add('Test '+ i);

Try below code;
public class StringArrayTest 
{
    public static list<string> generateStringArray(integer n)
    {
           list<string> t =new list<string>();
           for(integer i =0;i<n; i++)
           {
               t.add('Test '+ i);
               
            }
             return t;     
    }

}

 
Amit Chaudhary 8Amit Chaudhary 8
Please mark the best Answer if your issue is resolved. Else let us know if  you need more help