This forum is now read-only. Please use our new forums at discuss.codecademy.com.

While Loops in PHP Forum

View Course » View Exercise

85 points
521e65b39a7b1858905848aff1689ebc?s=140&d=retro
Submitted by
junayed
over 3 years ago

[resolved] 5/7 I am confused about the result, it only flips one and the result is tail

As the condition said that the coin will flip until the result is H or head then how come the result come as T or tail and stop flipping the coin and says "There was one flip". Any body found this? Can someone clear me?Thanks.


0 votes

permalink

The condition says: "while the result is heads" not "until the result is heads". So it will keep flipping as long as rand(0,1) produces a 1 (a head). As soon as you get a 0 (a tail) it echos that and then it stops.

3691 points
55df2afa95e3787b9200005e_359368177
Submitted by
Judy
over 3 years ago

2 Comments

521e65b39a7b1858905848aff1689ebc?s=140&d=retro junayed over 3 years ago

ok, thank you for the answer. Now it is clear.

55df2afa95e3787b9200005e_359368177 Judy over 3 years ago

You're welcome, I'm glad it helped.


0 votes

permalink

i still don't understand this. It is a bit confusing how the developers are teaching this. Why not just say completely stop at tails, when the FIRST tails appears, regardless of heads showing or not?

272 points
0ace99e1bbd2d0230bdad1652fcd7c2e?s=140&d=retro
Submitted by
chengitis
about 3 years ago