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 trialDochian Thomas
4,846 PointsHow do i solve Challenge Task 1 of 1 for the Pagination Course?
Pleas help!!
<?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) {
if ($count_less_than_one > $number) {
count($numbers);
}
if ($count_between_one_and_thousand > 0 AND $count_between_one_and_thousand < 1001) {
count($number);
}
$count_greater_than_thousand += 1;
}
include('view.php');
?>
5 Answers
jcorum
71,830 PointsSomething more along these lines:
foreach ($numbers as $number) {
if ($number < 1) {
$count_less_than_one += 1;
} else if ($number <= 1000) {
$count_between_one_and_thousand += 1;
} else {
$count_greater_than_thousand += 1;
}
}
$count_less_than_one, $count_between_one_and_thousand, and $count_greater_than_thousand are accumulators, and shouldn't be in the condition of if(), else if() or else().
Dochian Thomas
4,846 PointsWow thanks man. But does "+=" act the same as "++"
jcorum
71,830 PointsNot quite.
sum++ is short for sum = sum + 1
sum += n is short for sum = sum + n
So sum = sum + 1 can be shortened to either sum++ or sum += 1, but sum = sum + 2 can only be shortened to sum += 2
Dochian Thomas
4,846 PointsOh... I got you. Was looking it up and couldn't find what it stood for. Thanks.
jcorum
71,830 PointsYou are welcome.