C# C# Collections Lists Lists

Fredrik Rönnehag
Fredrik Rönnehag
2,341 Points

The item at index 1 should be 2

So I'm getting the error message item at index 1 should be 2. The index 1 is equal to 2, so I don't understand why I get this error.

MathHelpers.cs
using System.Collections.Generic;

namespace Treehouse.CodeChallenges
{
    public static class MathHelpers
    {
        public static List<int> GetPowersOf2(int num)
        {
            return new List<int>(5){
              (int)System.Math.Pow(num, 0),
              (int)System.Math.Pow(num, 0.5),
              (int)System.Math.Pow(num, 1),
              (int)System.Math.Pow(num, 1.5),
              (int)System.Math.Pow(num, 2)
            };

        }
    }
}

// Error message: item at index 1 should be 2.

// This returns list as 1, 2, 4, 8, 16 if the value 4 is passed in.

1 Answer

Steven Parker
Steven Parker
171,137 Points

Here's a few hints:

  • the list should contain "powers of 2" (not powers of "num")
  • the list should have a variable size "...from 0 to the value passed in"
  • you won't need any fractional exponents
  • you might need to use a loop