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# C# Collections Lists Lists

Calvin Secrest
Calvin Secrest
24,815 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

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
24,815 Points

Thank you for this assistance!

You're welcome :)