var discount = Math.floor((Math.random()*5) + 5); 

Closed due to the fact that the essence of the issue is incomprehensible by the participants of Kromster , Alexey Shimansky , insolor , user207618, AK Jun 20 '17 at 15:31 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • four
    What is your specific question for this formula, except for those that can be clearly read in the documentation for the floor and random functions. The course of arithmetic is difficult? - teran
  • @teran - why did you not mention the operators * and + and the signs ( , ) and = ? - Igor
  • @Igor attributed them to arithmetic :) - teran
  • Guys, but you can somehow be more respectful and patient to beginners. Do not want to answer - do not answer. Here, in the answer all chewed for a couple of paragraphs. And do not close on contrived occasions. - Vadim Ovchinnikov

1 answer 1

Math.random() function generates a random number in the range [0;1)
i.e., 0 <= Math.random() < 1
multiply by 5, we get: 0 <= Math.random()*5 < 5
add 5, we get: 5 <= (Math.random()*5) + 5 < 10
the Math.floor() function retrieves the integer part of a number (according to help, returns the largest integer that is less than or equal to the argument),
accordingly, a random number in the range [5;9] (from 5 to 9, including both borders) will be written to the variable discount