Ask Question
9 May, 00:16

What does the following code segment do?

var count = 0;

var sevens = 0;

while (count<100)

{

var roll1 = Math. floor (Math. random () * 6+1);

var roll2 = Math. floor (Math. random () * 6+1);

if (roll1 + roll2 = = 7)

sevens = sevens + 1;

}

+4
Answers (1)
  1. 9 May, 00:29
    0
    Hi!

    var count = 0; / /initialize count.

    var sevens = 0; / /initialize sevens.

    while (count<100) / / loops while count is minor than 100. * counts never add 1 at the final of the loop, so this while is always true.

    {

    //Math. floor (x) round to the max Integer a number. Example : 45.90 - > 46.

    //Math. random () returns a number between [0, 1).

    var roll1 = Math. floor (Math. random () * 6+1); / /Gets a integer using Math. random (), adds 1, and round it withMath. floor () then saves in roll1.

    var roll2 = Math. floor (Math. random () * 6+1); / /Gets a integer using Math. random (), adds 1, and round it withMath. floor () then saves in roll2.

    if (roll1 + roll2 = = 7) / /If the sum of roll1 and roll2 is 7 adds 1 to sevens.

    sevens = sevens + 1;

    }

    //*count is not incremented, so while (count always true.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “What does the following code segment do? var count = 0; var sevens = 0; while (count ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers