jQuery/JavaScript not working inside script tags

html, javascript, jquery

Solution

The script tag cannot have the src attribute and a body, you need to use separate script tags

<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script>
$(document).ready(function () {
    $("#d4").click(function () {
        var out = Math.random(1, 4);
        alert(out);
    }); //missing ) here
});
</script>

Script src

This attribute specifies the URI of an external script; this can be used as an alternative to embedding a script directly within a document. script elements with an src attribute specified should not have a script embedded within its tags.

Problem

I want, my HTML document to output random numbers for Dungeons and Dragons. However, the code isn't working and I can't workout why. ``` <!DOCTYPE html> <html> <head> <script src="//code.jquery.com/jquery-1.10.2.js"> $(document).ready(function(){ $("#d4").click(function(){ var out = Math.random(1,4); alert(out); }; }); </script> </head> <body> <p id ="d4">Roll a d4</p> </body> </html> ```

Original source