Hey guys! So I’m getting ready for my first junior dev interviews and I came across a practice question.

The premise is that I need to write code for rolling 5 dice until I get a Yahtzee (meaning I get the same result from all 5 dice). I’m pretty new to PHP so I’m taking it step by step. I figured out how to write code to generate a random value out of an array of 6 … essentially like rolling a single die. I know how I could make the function run 5 times. But I’m not sure about the next step… how would I compare the outputs of this function being run 5 times?

The attached screenshot is what I came up with so far, where the “condition” in the “do… while” loop is the thing I don’t know how to define.

If anyone has any ideas for how to achieve what I’m trying to achieve, or even how you would approach the question, I would be really grateful! Thank you guys!

Post image

Source link

Write A Comment