Incorrect code being approved by Code Academy?!


#1



Unit 6 excercise 6


Hi guys... This code is being approved in this excercise... Notice the double parantheses in the while code. I only placed this in there because I got a hint that I was missing parantheses. Never before this excercise have I seen duble parantheses so I wonder if this code is even correct?!! Even though it has been approved by Code Academy..


<!DOCTYPE html>
<html>
    <head>
		<title>Much a do-while</title>
	</head>
	<body>
    <?php
		$loopCond = false;
		do 
			{echo "<p>The loop ran even though the loop condition is false.</p>";}
		while (($loopCond)=false);
		$loopCond = true;
		
		echo "<p>Now the loop is done running.</p>";
    ?>
    </body>
</html>


#2

There are many problems with this code, including ($loopCond)=false, and $loopCond = true: First, an equal comparison opperator is ==, not =; Second, the parentisis are unnecessary; Third, with the loop set this way, if you had coded it right, it would have made an infinite loop. And fourth, the line $loopCond = true will do nothing to affect the loop.


#3

Hi Dan, first of all thanks for responding to this problem, and thanks for proving my point. I agree with you that this code is wrong. But my question remains:

  • WHY is this bad code being APPROVED by Code Academy?!

As you can see here CA is telling me that bad code is correct :
http://postimg.org/image/rnqwupoch/

Second of all, why does this code cause an infinite loop? I am stating that under the condition that $loopcon is FALSE the loop will run... After this I declare that $loopcon is TRUE so this makes the loop stop , correct? If this is not correct then again CA has approved wrong code again in excercises 6.2 and 6.3 of the PHP section...

Greets


#4

It's actually not approved by Codecademy. Although it lets you go to the next lesson. Have a look:

I think you are right the $loopcon stops the thing. But overall makes no sense. Anyway, what is your point?


#5

@mashuk Wrong! Codecademy does approve it, your computer recognizes that the code is bad.

@oscar_vv I believe that it's just checking to see that the loop runs once, then exits, so it sees that this happens, and doesn't care about the error.

Your $loopCond = true never gets a chance to run, because the loop comes first, and the computer ignores any code beneath until the loop is done.


#6

Do you have a facebook account "mashuk"?


#7

@dantemp: Hmm, I would be worried if it let you go to the next lesson without showing the error. But I think we are now speaking from two different perspective.
I agree in do while loop the "do" bit runs at least once.

@textpro15145: I do not use facebook.


#8

Hi Mashuk,

as Dan explained: PHP's standard error report shows the error, not Code Academy. Therefore Code Academy DOES approve the code. My point is that it is harmful to let students progress to the next excercise after inserting incorrect code. The code that I put in was incorrect by any standard but I still progressed to the next assignment. I hope you understand now because I do not know a way to explain this any clearer.

Dan thank you for your elaborate explanation, I have come to a better understanding of this PHP section and that is what this forum should be all about.

Do we agree that this code is correct?








<?php
$loopCond = false;
do
{echo "

The loop ran even though the loop condition is false.

";}
while ($loopCond==true);
	echo "<p>Now the loop is done running.</p>";
?>
</body>


#9

Yes, your code is correct now. But consider server side (php)/client side. That might be a reason that the error shows in the display.


#10

Yup, that looks good.


#11

Awesome, that means we can close this topic :wink: The code I mentioned that is correct does not get approved by CA in excercise 6.6.. I hope you can talk to your programmers and have it fixed because this can be confusing for students. Let me end by saying that even though I have my critique I think CA is AWESOME for helping us code students in improving with this free programme... I will go pro for sure after I finish this course.

Greets from the Netherlands


#12

Sorry, it's almost right. You're missing the <p> tags here...