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 trialomer cohen
2,549 Pointsno matter what it display me the same massage
i put this code below and it always display me that massage : "please enter a student name"
regards omer
this is the code :
<?php
$firstname ='omer ';
$lastname ='cohen ' ;
$currentgrade=9;
$finalaverage=80;
$massagebody=' ' ;
if($firstname||!$lastname){
echo 'please enter a student name';
}
elseif ($currentgrade<9||$currentgrade>12){
echo 'this is for only high school student.
please enter grade between 9 and 12 ';
}
else{
if($finalaverge<.70){
$massagebody='We look forward to seeing you at summer school, beginning July 1st! ';
}
else{
switch ($currentgrade){
case 9:
$massagebody='Congratulations on completing your freshman year in High School! Weāll see you on September 1st for the start of your sophomore year! ';
break;
case 10:
$massagebody='Congratulations on completing your sophomore year in High School! Weāll see you on September 1st for the start of your junior year! ';
break;
case 11:
$massagebody='Congratulations on completing your junior year in High School! Weāll see you on September 1st for the start of your senior year! ';
break;
case 12:
$massagebody='Congratulations! Youāve graduated High School! Donāt forget to come back and visit. ';
break;
default:
$massagebody='error:grade level is not 9-12';
break;
}
}
echo "dear $firstname $lastname\n";
echo $massagebody;
}
?>
Moderator edited: Added markdown to properly render the code on the forums.
5 Answers
Jennifer Nordell
Treehouse TeacherHi again, Omer! To answer your question, yes, given your current code, it will always display that message. And here's the block of code that's doing it:
if($firstname||!$lastname){ // If firstname is NOT empty OR lastname is empty
echo 'please enter a student name';
}
What it should be asking is if either the first name is empty or the last name is empty, please fill out the student's name:
if(!$firstname||!$lastname){ //If firstname is empty OR lastname is empty. ... you forgot a ! in this line
echo 'please enter a student name';
}
If you make that correction, you should see the message disappear.
Hope this helps!
omer cohen
2,549 Pointsthanks jeniffer but it still have this notice from console this one : PHP Notice: Undefined variable: finalaverge in /home/treehouse/workspace/school.php on line 35
Notice: Undefined variable: finalaverge in /home
/treehouse/workspace/school.php on line 35
dear omer cohen
We look forward to seeing you at summer school,
beginning July 1st!
this is the code :(there is an error on line 35 )
$firstname ='omer ';
$lastname ='cohen ' ;
$currentgrade=9;
$finalaverage=80;
$massagebody=' ' ;
if(!$firstname ||!$lastname){
echo 'please enter a student name';
}
elseif ($currentgrade<9||$currentgrade>12){
echo 'this is for only high school student.
please enter grade between 9 and 12 ';
}
else{
if($finalaverge<.70){
$massagebody='We look forward to seeing you at summer school, beginning July 1st! ';
}
else{
switch ($currentgrade){
case 9:
$massagebody='Congratulations on completing your freshman year in High School! Weāll see you on September 1st for the start of your sophomore year! ';
break;
case 10:
$massagebody='Congratulations on completing your sophomore year in High School! Weāll see you on September 1st for the start of your junior year! ';
break;
case 11:
$massagebody='Congratulations on completing your junior year in High School! Weāll see you on September 1st for the start of your senior year! ';
break;
case 12:
$massagebody='Congratulations! Youāve graduated High School! Donāt forget to come back and visit. ';
break;
default:
$massagebody='error:grade level is not 9-12';
break;
}
}
echo "dear $firstname $lastname\n";
echo $massagebody;
}
?>
Moderator edited: Markdown added to code to render properly on the forums.
Jennifer Nordell
Treehouse TeacherHi again, Omer! The error you're receiving now is about an undefined variable. And this is because you've made a typo.
In your original declaration of the variable you typed this:
$finalaverage=80;
But when you try to use that variable again in a condition, there's a misspelling. Here's your code:
if($finalaverge<.70){
That should be:
if($finalaverage<.70){ //note the additional 'a' between the 'r' and 'g'
Hope this helps!
omer cohen
2,549 Pointsthank you princess .
omer cohen
2,549 Pointsjennifer can you help me with that post i wrote here : https://teamtreehouse.com/community/switch-if-statement-to-switch-statement
on bottom of the page .
regards omer
Jennifer Nordell
Treehouse TeacherIf you would like an answer to that, it would be better to post it as an entirely new question. This has a few benefits. It helps others see that you have a new pending question and helps keep the forums organized. Also, that question was originally posted 8 months ago and challenges are changed and updated frequently. The code that passed that challenge yesterday might not pass today. Make sure you link the challenge in your new question!
omer cohen
2,549 Pointsthanks jennifer here is the post :https://teamtreehouse.com/community/why-do-i-get-that-syntax-error-on-line-16-it-is-the-end-of-the-code someone has reply i did what he say and it does not work . can you write it for me ?
regards omer
Jennifer Nordell
Treehouse TeacherJennifer Nordell
Treehouse TeacherHi Omer! I added some markdown to your code so that it will properly display here on the forums. Check out the Markdown Cheatsheet at the bottom of the "Add an Answer" section. It contains some great instructions on how to format your questions and answers for the forums!