Ask Question
8 September, 04:33

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.

+1
Answers (1)
  1. 8 September, 04:47
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers