Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C#

Name:GoogleSearch orJonathan Sum
Name:GoogleSearch orJonathan Sum
5,039 Points

I have tried this code code changlle for two days. It is still saying it won't work or it won't pass. Post the code if..

In the previous video there is no videos about C# method or creating a sub class in C#. The only sub class of C# is done in the console in the C# array tutorial. I can only finish this code changlle in the console. I can't finish this in the working space. In "some" of treehouse course, there is still something that doesn't explain totally ,or it doesn't even be explained more than 5 sec. There is not video focus on C# For Loop ,and there is a array video using for loop and explain for loop within 5 sec. It is just like how the python object class explaining "__ main " in 5 sec,and i need to watching Youtube tutorial about " main __" for hours in order to understant what the hell he is talking about. That is why Most of peopel saying treehouse is only good for beginner.

If you can ,just post the correct code for me, PLZ. I am totally surrendered

namespace Treehouse.CodeChallenges
{
    public static class MathHelpers
    {

        public static int[][] BuildMultiplicationTable(int maxFactor)
        {
            int m1= maxFactor+1;
                int[][] BuildMultiplicationTable1 = new int[m1][]; //setting a array
                BuildMultiplicationTable1[0] = new int[m1];
            for(int rowIndex = 0; rowIndex < BuildMultiplicationTable1.Length; rowIndex++)
            {

                for(int colIndex = 0; colIndex < BuildMultiplicationTable1[rowIndex].Length; colIndex++)
                {
                    maxFactor[rowIndex][colIndex] = rowIndex*colIndex;
                }
            }   
            return BuildMultiplicationTable1;


        }

    }
}
Simon Coates
Simon Coates
28,694 Points

not familiar with c#. Is the answer posted at https://teamtreehouse.com/community/mutlidimensional-array-code-challenge for the right challenge? Might give you some hints.

Steven Parker
Steven Parker
231,210 Points

I think the word for that is "spoiler", not "hints". :stuck_out_tongue_winking_eye: But the good news is no, that's for a different challenge.

Give a man a fish and you feed him for a day; teach a man to fish and you feed him for a lifetime. :fishing_pole_and_fish:
    ― Maimonides

Simon Coates
Simon Coates
28,694 Points

sorry steven, I think you posted after i'd already navigated to this post and was googling. Wasn't my intention to short circuit your assistance.

5 Answers

Steven Parker
Steven Parker
231,210 Points

It doesn't look like you have applied the third hint I gave you last time you asked this.

I will repeat it for you here, with one more hint:

  • on line 17 you attempt to subscript the ordinary integer maxFactor (where you probably want the array)
  • on line 10 you initialize the first row of the array, but you never initialize the other rows.

Also, you do not need a sub class for this challenge.

You're actually pretty close. Once you fix these two issues you will pass the challenge.

Name:GoogleSearch orJonathan Sum
Name:GoogleSearch orJonathan Sum
5,039 Points

Like i said , there is not video about C# function. I can't do anything if there is not video about it. I am glad that u tried to help me. However, if u are not sure what to do, just... idk. If u click this link "https://teamtreehouse.com/library/c-collections/arrays/jagged-arrays" ,u will see that is no semicolon on line 8. It means....

Steven Parker
Steven Parker
231,210 Points

I see you did apply the first two hints I gave you last time, but haven't done the third yet. Plus I've given you one more.

And I'm absolutely certain that fixing these issues will do the trick — because I put your code into the challenge, fixed these issues, and it did pass.

Name:GoogleSearch orJonathan Sum
Name:GoogleSearch orJonathan Sum
5,039 Points

@steven parker. I really appreciate that u tried to help me. However, i don't think u can help me ,or i think u are not sure what to do.

Once again, there is no C# function tutorial in the previous videos. I can't do anything about the C# function at all if the function from about is wrong. It is just like i cant speak spanish without learning it at all.

i don't think treehouse is going to work if i only learn here. Some of treehouse instructor haven't taught coding before ,and when they have seen they are missing something ,they just pass it. I have seen a lot of people here that they have done a lot of advanced coding courses. That is why their coding challenge answers even use something that the instructor haven't even taught about it. Sometimes i even have to learn their coding challenge answer in order to pass the coding chanllenge. Let me say one more thing.

No matter the python class or C# ,instructor always doesn't explain for loop detailly. When they are using a For loop ,they always use a friendly key word ,such as using "product" in a for loop "for product in Best selling product". This kind of doing always makes me confuse. It is just like thinking that the product is a key word as "class" or "int". I will keep in mind that i cant change the word "product". In fact there is a whole long story in for loop. However, most or i guess all of treehouse instructors doesn't want to explain it at all. They always think using the "friendly word" is going to solve the problem.

steven parker, Can u tell me if treehouse can't be the only way to learn to code ,what is the other way to learn to code?

Name:GoogleSearch orJonathan Sum
Name:GoogleSearch orJonathan Sum
5,039 Points

line ten is for (int row = 0; row < multiplicationTable.Length; row++) and line 17 is a " } " sign

Name:GoogleSearch orJonathan Sum
Name:GoogleSearch orJonathan Sum
5,039 Points

I even made a 9 by 9 maxtrics in the Console since the array video was taught in the Console.

//It works in REPL. it prints 
0000000000
0123456789
024681012141618
0369121518212427
04812162024283236
051015202530354045
061218243036424854
071421283542495663
081624324048566472
091827364554637281

//However, it doesn't work when i try to run this code.  
namespace Treehouse class Cell3 {

int[][] sheet = new int[10][];
sheet[0] = new int[10];
for(int rowIndex = 0; rowIndex < sheet.Length; rowIndex++)
{
    sheet[rowIndex] = new int[10]; //creata row of 10 cells
    for(int colIndex = 0; colIndex < sheet[rowIndex].Length; colIndex++)
    {
        sheet[rowIndex][colIndex] = rowIndex*colIndex;

    }
}
Simon Coates
Simon Coates
28,694 Points

the 2d array is an array of arrays, so BuildMultiplicationTable1[0] = new int[m1]; should be moved and altered slightly. (needs to happen on each row, which is similar to your 9 by 9 maxtrics code). Apart from this, the only thing i did to get your code to work was get rid of one use of maxFactor name instead of the array variable (and simplify some variable usage).

(so steven's two suggested changes were exactly right)

Name:GoogleSearch orJonathan Sum
Name:GoogleSearch orJonathan Sum
5,039 Points

I just finished with this correct code

namespace Treehouse.CodeChallenges
{
    public static class MathHelpers
    {

        public static int[][] BuildMultiplicationTable(int maxFactor)
        {
            int m1 = maxFactor + 1;
            int[][] BuildMultiplicationTable1 = new int[m1][]; //setting a array or this one is useless
            BuildMultiplicationTable1[0] = new int[m1];
            for (int rowIndex = 0; rowIndex < BuildMultiplicationTable1.Length; rowIndex++)
            {
                BuildMultiplicationTable1[rowIndex] = new int[m1];          / /Correction-1 This line of code was not even here. I forget to add inter array into each outter array.  Now i know why steven said "You never initialize the other rows.' , but this line of code was in line 9 not line 10
                for (int colIndex = 0; colIndex < BuildMultiplicationTable1[rowIndex].Length; colIndex++)
                {
                    BuildMultiplicationTable1[rowIndex][colIndex] = rowIndex * colIndex;     //Correction-2 it was  maxFactor instead of maxFactor. now i understant why steven said ordinary integer maxFactor ,but he said it is in line 17. infact, this is in line 16.
                }
            }
            return BuildMultiplicationTable1;


        }

    }
}
Simon Coates
Simon Coates
28,694 Points

i got

namespace Treehouse.CodeChallenges
{
    public static class MathHelpers
    {

        public static int[][] BuildMultiplicationTable(int maxFactor)
        {
            int m1= maxFactor+1;
            int[][] BuildMultiplicationTable1 = new int[m1][]; //setting a array

            for(int rowIndex = 0; rowIndex < m1; rowIndex++)
            {
                BuildMultiplicationTable1[rowIndex] = new int[m1];
                for(int colIndex = 0; colIndex < m1; colIndex++)
                {
                    BuildMultiplicationTable1[rowIndex][colIndex] = rowIndex*colIndex;
                }
            }   
            return BuildMultiplicationTable1;
        }
    }
}

Pretty much the same, but looks simple due to using m1.

Name:GoogleSearch orJonathan Sum
Name:GoogleSearch orJonathan Sum
5,039 Points

@Steven parke thx for help again. u r right. it is just the line location u gave me is wrong.

Steven Parker
Steven Parker
231,210 Points

Glad to hear you got it. :star2:

Programming is enough of a challenge on its own even when the information is in your own language!