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
Joe Shiels
19,933 PointsAdjusting Invalid Numbers
Hi, I am completely stuck on the "Adjusting Invalid Numbers" code challenge in the new PHP Pagination stage. Could anybody help?
2 Answers
Randy Hoyt
Treehouse Guest TeacherHere's a link, for reference:
Would you mind posting the code you have so far?
There are one thousand numbers in the array called $numbers. Some of those numbers are less than 1, some of them are between 1 and 1000, and some of them are greater than 1000. The code challenge is asking you to figure out how many of them fit into each of these categories.
Start with the first category. What code would you write to check if a number was less than one? In the preview on the right, it says there are one thousand numbers that are less than one. That displays the number in the $count_less_than_one variable. How is that number being calculated? Why is it counting all the numbers? What would you need to do to make it only count numbers that are actually less than one?
JUAN VARGAS
17,801 PointsHey Joe, you are almost there, you are just missing one thing:
<?php
require_once('model.php');
$numbers = get_numbers();
$count_less_than_one = 0;
$count_between_one_and_thousand = 0;
$count_greater_than_thousand = 0;
foreach ($numbers as $number) {
$count_less_than_one += $number < 1;
$count_between_one_and_thousand += $number >= 1 && $number <= 1000; /*comparison needs to include 1 & 1000*/
$count_greater_than_thousand += $number > 1000;
}
include('view.php');
?>
your comparison was not correct..
Joe Shiels
19,933 PointsThanks Juan!
Joe Shiels
19,933 PointsJoe Shiels
19,933 PointsHere is my code so far:
I am getting the error "It looks like you are ignoring the numbers 1 and 1000 right now. Be sure to include them in category (a)."