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 trialFredrik Rönnehag
2,342 PointsThe 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.
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
231,198 PointsHere'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
Fredrik Rönnehag
2,342 PointsFredrik Rönnehag
2,342 PointsGot it, thanks! :)