Ask Question
17 December, 20:12

What does the following code segment do?

var isSeven = false;

while (isSeven==false)

{

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

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

if (roll1 + roll2 = =7)

{

isSeven = true;

alert (roll1 + "--"+roll2);

}

}

It keeps generating two random numbers of any values until the sum of the two numbers is 7.

It keeps generateing two random numbers between 1 and 6, and adds up the two numbers.

It keeps generating two random numbers between 1 and 6, until the sum of the two numbers is 7.

It keeps generating two random numbers between 1 and 6, then check if the sum of the two numbers is 7.

+2
Answers (1)
  1. 17 December, 21:21
    0
    It keeps generating two random numbers between 1 and 6, until the sum of the two numbers is 7.

    Explanation:

    isSeven is always false until the sum of roll1 and roll2 is seven.

    Math. random () generates a number between 0 and 1 where 1 is exclusive and 0 is inclusive and multiplying it with 6 means that it will generate the number between 0 and 5 and adding 1 means a number between 0 and 6.

    Math. floor () is to consider the lower bound integer of the float value for 1.9 it will consider 1 only.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “What does the following code segment do? var isSeven = false; while (isSeven==false) { var roll1=Math. floor (Math. random () * 6+1); var ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers