lundi 6 mars 2017

Math.pow with exponent being Math.random

I just want to know how to make Math.sqrt, Math.cbrt, Math.pow or whatever to have the value in the () be Math.random. Example:

<!DOCTYPE html>
<html>
<body>
    <button onclick="myFunction()">Broken...</button>
    <p id="demo"></p>
    <script>
        function myFunction() {
            document.getElementById("demo").innerHTML = ((Math.cbrt(Math.random) * 1) + 0);
        }
    </script>
</body>
</html>

This just results in NaN (Not a Number).

PS. I know the onclick attribute is unprofessional, but .onclick isn't working. Maybe the jQuery equivalent might work.




Aucun commentaire:

Enregistrer un commentaire