C# C# Collections Lists Lists

Calvin Secrest
Calvin Secrest
20,719 Points

Getting Past the C# List<T> for list of integers Challange

The code below works fine in the IDE, but will not let me pass the challenge.

Directions: "Create a static method named GetPowersOf2 that returns a list of powers of 2 from 0 to the value passed in. So if 4 was passed in, the function would return { 1, 2, 4, 8, 16 }. The System.Math.Pow method will come in handy."

Error: " Bummer! Does MathHelpers.GetPowersOf2 return List`1?"

Does anyone now what the Code Challenge is looking for (besides what its asking)

Thanks

MathHelpers.cs
using System.Collections.Generic;
using System;

namespace Treehouse.CodeChallenges
{
    public static class MathHelpers
    {
        public static List<int> GetPowersOf2(int input)
        {
            var returnList = new List<double>();
            for (int 1 = 0; i <= input; i++)
            {
                returnList.Add((int)Math.Pow(2, i));
            }   
        }
    }
}

2 Answers

Eduardo Parra San Jose
Eduardo Parra San Jose
12,573 Points

Hi,

I hope the following tips helps out to solve the challenge:

  • The GetPowersOf2 method performs actions but it doesn't include a return statement to return the List
  • Variable names cannot start with a number, so in the for loop the variable cannot be called 1, I guess what you wanted was to call it i
  • In the signature of the method it says a list of int will be returned, but the returnList type is a list of double

Many thanks. Have a nice day, edu

Calvin Secrest
Calvin Secrest
20,719 Points

Thank you for this assistance!