There is a function

var rund = function rand(min, max) { return Math.floor(Math.random() * (max - min + 1) + min); } 

For example, you can call it like this:

 alert(rand(10,20)); 

But I need the following

 var srotate = "rotate(" + Результат вызова функции rand + "deg)"; $(".hour").css({"-moz-transform" : srotate, "-webkit-transform" : srotate}); 

How to do it?!

  • @DreamChild or maybe it's better to just set rand ()? Why create an extra variable? - intro94
  • one
    @ intro94 razsmeetsya better. However, the example was written based on the code given in the question DreamChild
  • @DreamChild is also an option. :) - intro94
  • five
    Well, the questions went: Rudder: - MDJHD

3 answers 3

Here is the working version:

 var srotate = "rotate(" + rand(10,20) + "deg)"; 

As another option, you can use the DreamChild clause, I decided to add this option. :)

    uh ... and just the type assignment

     var val = rand(10,20) var srotate = "rotate(" + val + "deg)"; 

    no longer in vogue?

    • Yes, everything is in fashion. I did that. But the code does not work. And now I tried all two options. The result is the same. ReferenceError: rand is not defined var val = rand (10,20); - HoPkInS
    • @HoPkInS then show the code what you are doing and how. Apparently you are missing something in the code behind your backstage. In the options proposed here, errors, except for syntax, there is no place to take - all more than elementary - DreamChild

    There are no "curtains" net.vtavil such a code and it all worked.

      function rand(min, max) { return Math.floor(Math.random() * (max - min + 1) + min); } var val = rand(0,180); var srotate = "rotate(" + val + "deg)"; $(".hour").css({"-moz-transform" : srotate, "-webkit-transform" : srotate}); 
    • so what's the difference? It looks exactly the same as what was offered to you in responses and comments - DreamChild
    • @DreamChild. In fact of the matter. I said that I did the same, but it did not work for me. Therefore, he asked. I thought maybe I was mistaken in something. And the difference is this. It was var rund = function rand (min, max). It has become you can see how. - HoPkInS