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
Manohar kumarManohar kumar 

Problem with Verifing trailhead Module

Hi All,

I am having problem with verifing this module.Its very simple but i am not able to verify this.
Module:

Create an Apex class that returns an array (or list) of formatted strings ('Test 0', 'Test 1', ...). The length of the array is determined by an integer parameter.
The Apex class must be called 'StringArrayTest' and be in the public scope.
The Apex class must have a public static method called 'generateStringArray'.
The 'generateStringArray' method must return an array (or list) of strings. Each string must have a value in the format 'Test n' where n is the index of the current string in the array. The number of returned strings is specified by the integer parameter to the 'generateStringArray' method.
 

public class StringArrayTest {
    public Static List<string> generateStringArray(Integer n){
        integer i=1;
        List<String> rtn = new List<String>();
        for(i =1;i<=n;i++){
        rtn.add('\'Test '+i+'\'');
        }
        return rtn;
    }
}
Best Answer chosen by Manohar kumar
Siddharth ManiSiddharth Mani
You are not generating 'Test 0' as one of the outputs. Also the single quotes ('') is not needed in the final output - That is just for reference. Change those two and I guess it should be fine:
public class StringArrayTest {
    public static List<String> generateStringArray(Integer n) {
    List<String> myString = new List<String>();
        for (Integer j=0;j<n;j++) {
            myString.add('Test '+ j);
        }
        return myString;
    }
    
}

 

All Answers

Srinivas SSrinivas S
Please replace i value from 1 to 0.
public class StringArrayTest {
    public Static List<string> generateStringArray(Integer n){
        integer i=0;
        List<String> rtn = new List<String>();
        for(i =0;i<n;i++){
        rtn.add('\'Test '+i+'\'');
        }
        return rtn;
    }
}

-------------------
Thanks,
Srinivas
- Please mark as solution if your problem is resolved.
Siddharth ManiSiddharth Mani
You are not generating 'Test 0' as one of the outputs. Also the single quotes ('') is not needed in the final output - That is just for reference. Change those two and I guess it should be fine:
public class StringArrayTest {
    public static List<String> generateStringArray(Integer n) {
    List<String> myString = new List<String>();
        for (Integer j=0;j<n;j++) {
            myString.add('Test '+ j);
        }
        return myString;
    }
    
}

 
This was selected as the best answer
Amit Chaudhary 8Amit Chaudhary 8
Hi Manohar kumar,

Please check below post for same issue
1) https://developer.salesforce.com/forums/?id=906F0000000BTQ9IAO

Please try below code:-
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;
    }
}
And go :
Your Name>Developer Console>Debug>Open Execute Anonymous Window 
Paste below code in it
list<string> myArray = StringArrayTest.generateStringArray(10);
system.debug('************'+myArray);
Let us know if this will help you

Thanks
AMit Chaudhary


 
Manohar kumarManohar kumar

Thanks Siddharth Mani... that helped thank you for your reply.That worked perfectly.

@Srinivasa Reddy S i tried with 0 but it did not worked . i am sorry i should be more specific in my post.

@Amit Chaudhary  thanks for your reply.