This forum is now read-only. Please use our new forums! Go to forums

0 points
Submitted by Dujon
almost 11 years

It accepts a wrong code

Answer 51637ce3bff786888b000568

0 votes

Permalink

The instructions say write a comparison that returns true. 8 > 5 is true.

points
Submitted by Jason Travis
almost 11 years

2 comments

Dujon almost 11 years

oh so what i have got there is right? lol

Karl Alexis almost 10 years

yes what you did was correct, but the instructions are incorrect, it wants a value less than 5 rather than greater (I believe it’s an error). It will give the value of true.

Answer 52c991de7c82ca5f5c006330

0 votes

Permalink

It gets worse. I passed typing in the following:

$var = 6; var < 7;

Here’s where PHP gets weird. So, ‘var’ is not the same thing as ‘$var’. ‘$var’ is a variable, and ‘var’ is a string. In PHP, strings have the numeric value of 0. (In Javascript, IIRC, strings have the numeric value of 1, so this is not a language-specific thing.) Technically, “var < 7” resolves to TRUE, even though we’re actually comparing apples and oranges.

It’s almost as if we gave computers syntax, but forgot to give them all the rules. I highly recommend comparing different data types, just to see what will happen. I already mentioned strings and integers; find some more!

points
Submitted by Kenneth Westervelt
about 10 years

2 comments

Karl Alexis almost 10 years

it makes perfect sense, don’t you know the rules of PHP? you use $ before the variable name to instruct that it is indeed a variable

Thomas Gerot over 9 years

Karl is quite correct.