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
michelle emanuel 59michelle emanuel 59 

Getting Started with Apex

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.

the exercise was complete and ran and followed the instructions why were the points not awarded?
Best Answer chosen by michelle emanuel 59
William TranWilliam Tran
:-),

your testArray.add('Test'+ i+'\'' ); is off.

it should be testArray.add('Test '+ i );

See below for example:
 
public class StringArrayTest {
    
    public static List<String> generateStringArray(Integer n)
    {
        List<String> myArray = new List<String>();
        for(Integer i=0;i<n;i++)
        {
           myArray.add('Test '+i);
           System.debug(myArray[i]);
        }
        return myArray;
    }
}

As a common practice, if your question is answered, please choose 1 best answer.
But you can give every answer a thumb up if that answer is helpful to you.

Thanks

All Answers

William TranWilliam Tran
Can you post your code?

Thx
James LoghryJames Loghry
Also, when you post the code, please use the code format (< >) button.  :)
michelle emanuel 59michelle emanuel 59
<public class StringArrayTest {
    public static String[] generateStringArray (Integer n) {
        String[] testArray = new String[] {};
        for(Integer i=0;i<n;i++) {
          testArray.add('Test'+ i+'\'' );
          }
        System.debug(testArray);
        return testArray;
    }
}>
William TranWilliam Tran
:-),

your testArray.add('Test'+ i+'\'' ); is off.

it should be testArray.add('Test '+ i );

See below for example:
 
public class StringArrayTest {
    
    public static List<String> generateStringArray(Integer n)
    {
        List<String> myArray = new List<String>();
        for(Integer i=0;i<n;i++)
        {
           myArray.add('Test '+i);
           System.debug(myArray[i]);
        }
        return myArray;
    }
}

As a common practice, if your question is answered, please choose 1 best answer.
But you can give every answer a thumb up if that answer is helpful to you.

Thanks
This was selected as the best answer