140k views
1 vote
A student in correctly attempted to produce a random value in the range 1.6 using the expression.

6* ( int ) Math.random ( ) + 1

Correct the error in expression above to get the desired result.

Please answer it ASAP ​

1 Answer

4 votes

Answer:

The answer to this question is given below in the explanation section

Step-by-step explanation:

This is a javascript function. To return a value between the range of two numbers, we can use the following function "getRandom" that takes a minimum value and maximum value.

function getRandom(min, max) {

return Math.random() * (max - min) + min;

}

However, the correct code to produce a random value in the range of 1 to 6 using expression is :

Math.random() * (6-1) + 1;

this line of code return random number in rand of 1 to 6.

User Abhit
by
6.9k points