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 trialGareth Redfern
36,217 PointsPHP Code Challenge Help
Hi, I am really stuck on this code challenge can anyone help please:
4 Answers
Nick Stellato
Front End Web Development Techdegree Student 33,994 PointsGareth,
I took a look at what you posted. It seems that you need to add some if/else statements in order to control which count variable gets increased.
'''php <?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 $number is _____ */
$count_less_than_one += 1;
$count_between_one_and_thousand += 1;
$count_greater_than_thousand += 1;
}
include('view.php'); ?> '''
Gareth Redfern
36,217 PointsAhh O.K. thanks Nick, I have given this a try but it fails:
$count_less_than_one = 0;
$count_between_one_and_thousand = 0;
$count_greater_than_thousand = 0;
foreach ($numbers as $number) {
if ($number < 1) {
$count_less_than_one += 1;
}
if ($number >= 1 && $number <= 1000) {
$count_between_one_and_thousand += 1;
}
if ($number < 1000) {
$count_greater_than_thousand += 1;
}
}
J.L. Sparreboom
3,241 PointsWell Gareth you've solved the answer yourself you only made a slight typo fault.
Look at your last if block, it doens't say "greater" (>) than 1000 it actually says "less"(<) than 1000
Gareth Redfern
36,217 PointsAhh perfect thanks, J.L. so close but that fixed it!