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

PHP PHP Basics Daily Exercise Program Conditionals

== kind of, === exactly, != not ... Bummer! You need to check that $studentOneGPA is equal to 4.0

Perhaps I am confused on the meaning and usage of ==.

Here is the initial idea I had till I got an error then I tried the current code

  • if($studentOneName || $studentTwoName == $studentTwoGPA) { print $studentTwoName . " made the Honor Roll!"; }

else($studentOneName || $studentTwoName == $studentOneGPA) { print $studentOneName . "has a GPA of" . $studentOneGPA

}

Here is the second idea I had after doing some more reading.

if($studentOneGPA == $studentTwoGPA){ print "FOOKIN\' AWESOME $studentOneName you made it!"; } else($studentOneGPA != $studentTwoGPA){ print "I knew you would get a 4.0 GPA $studentTwoName."

}

as always ... input on this is welcomed and appreciated.

index.php
<?php
$studentOneName = 'Dave';
$studentOneGPA = 3.8;

$studentTwoName = 'Treasure';
$studentTwoGPA = 4.0;

//Place your code below this comment
if($studentOneGPA == $studentTwoGPA){
    print "FOOKIN\' AWESOME $studentOneName you made it!";
} else($studentOneGPA != $studentTwoGPA){
    print "I knew you would get a 4.0 GPA $studentTwoName."
}
?>

6 Answers

Dane Parchment
MOD
Dane Parchment
Treehouse Moderator 11,075 Points

Ok! Let me explain what the comparisons are that you are using now in PHP

== This one is just a basic comparison it checks and sees if the two things it is comparing are the same (but not in type). For example '1' == '1' is True however, '1' == 1 is True as well and that can possibly lead to errors as they are not the same type!

=== This one is the same as the == operator however, it differs in the sense that it will also check for type! So 1 == '1' is False which would be correct since they are not the same type.

!= Same as the == in the sense that it doesn't type check, it differs because it checks if the two thing it is comparing are not equal!

!== Same as != but it has type checking!


Using that knowledge I have a question for you. In terms of the challenge why are you comparing the two student's GPA's to eachother? The challenge is asking you to check and see if each student's GPA is equal to 4.0 not if each student's GPA is equal to eachother! Student Two happens to have a 4.0 GPA but they are not what we are comparing the other student grade's to. What if student two didn't have a 4.0, then you wouldn't be checking if the students had 4.0 GPAs would you?

I am not going to answer this challenge for you, as it seems that you have the programming knowledge necessary to tackle this question. But hopefully my explanation above and the logic breakdown will help you out!

Bummer! You need to check that $studentOneGPA is equal to 4.0 ... so I put == then I put === which I thought meant it had to be exactly alike.

I am not looking for a quick fix I have been reading through 3 different books, stackoverflow, css-tricks.com & php.net.

things normally come easy for me so sometimes when it happens to fast I second guess myself ... like ... that can't be the answer. I like to try to work things out even on paper before I try to smash the submit(save buttons). I have been reading a book called Think Like a programmer by V. Anton Spraul its written with C++ in mind. But the concepts can be applied to just about anything. I do not know C++, but figured its writings would help.

I do thank you for your time.

Dane Parchment
Dane Parchment
Treehouse Moderator 11,075 Points

You missed it! Read my comment on your logical reasoning. You are currently not checking if the studentOneGPA is equal to 4.0 are you? It wouldn't matter if you are using == or === at this point because you are not comparing the correct things in the first place.

Dane Parchment
Dane Parchment
Treehouse Moderator 11,075 Points

Also I just noticed this, but else statements do not contain actual comparisons, it would look like this instead:

if(a < b) {
do somthing....
}else {
do something else.....
}

I hadn't noticed that before! But remember that an else statement just basically the default statement that occurs whenever the previous if statements don't work out! If you want to do a comparison within your else statement then use elseif instead and do this:

if(a < b) {
do something....
}
elseif(a > b) {
do something else...
}
else {
both a > b and a < b are false do something else....
}

I am happy that you are working through the solutions on paper and seem to have an enthusiasm for this. But I think you are rushing through the exercise to quickly. Look carefully at the logic that you are coding and then look at what the question is asking you to do, and what the error is that you are being given! I will say it again, my hint to help you solve this problem is: Check and see if you are comparing the studentGPA to the correct value

Ok ... so I misunderstood what it was asking. Am I kind of hot, warm or still in the arctic waters. I guess you missed the title in this post. I even admitted in the first line below it ... Perhaps I am confused on the meaning and usage of ==.

so it wasnt a mystery that I was off ... which is why came here.

again I do thank you for your time.

Dane Parchment
Dane Parchment
Treehouse Moderator 11,075 Points

You are currently in cold waters my friend :(

But have no fear you are trickling towards warmer oceans! In my first answer I specify what the comparison values do! If you do not understand them then I recommend you go back and rewatch the videos that cover them! But again, even in regards to the question itself, it won't matter if you use == or === becuase you should be comparing a number to a number anyway!

You are correct in what you were saying I wasn't comparing them ... here are the comparison operators I found.

/ = equality % = inequality < = lesser than > = greater than <= = Less than or equal to >= = Greater than or equal to <=> = Returns an integer reflecting comparison

I'll post what I came up with shortly.

Thanks again for your input.

Dane Parchment
Dane Parchment
Treehouse Moderator 11,075 Points

You don't need any of those comparison operators though, literally all you need is either == or === both will do the same thing. The others are not necessary, not even the != or !== are needed for this exercise!

Here is what I came up with now, but i am still getting an error which states. Bummer! Use the variables to display the message.

<?php
$studentOneName = "Dave";
$studentOneGPA = 3.8;

if($studentOneGPA == 4.0){
    print $studentOneName . " made the Honor Roll.";
} else {
    print $studentOneName . " has a GPA of " . $studentOneGPA;
}
?>

<br/>

<?php
$studentTwoName = "Treasure";
$studentTwoGPA = 4.0;

if($studentTwoGPA == 4.0){
    print $studentTwoName . " made the Honor Roll.";
} else {
    print $studentOneName . " has a GPA of " . $studentTwoGPA;
}
?>

Here is a screenshot of my code in brackets and the result in chrome. http://prntscr.com/g7u39s

I am seriously at a loss at this point. I read through all kinds of documentation, stopped to take several breaks to try to clear my head etc. :(

https://www.youtube.com/watch?v=vh_gddKS5OU

Dane Parchment
Dane Parchment
Treehouse Moderator 11,075 Points

Here is where your issue lies, it should be pretty obvious what the mistake is!

print $studentOneName . " has a GPA of " . $studentTwoGPA;

Hint: You are trying to display Student Two's Name and GPA!

Dane Parchment
Dane Parchment
Treehouse Moderator 11,075 Points

Otherwise great job, you figured out what the issue was!

Dane Parchment
Dane Parchment
Treehouse Moderator 11,075 Points

Though I do not understand why you wrote them in two separate php programs. You can have the entire program within one <?php?> program!

i was trying to work through them both in chunks ... the book i am reading is recommending to break things down instead of trying to do the whole thing at once. I will definitely keep your advice in mind and slowly read the instructions

Thanks again for your help.