0
votes

 document.getElementById("button").onclick = function(){myFunction();

    function myFunction() {
      var random = Math.floor((Math.random() * 78) + 1);
      document.getElementById("demo").innerHTML = random;
    } // error is stated here
<!DOCTYPE html>
<html>
<head>
    <script type = "text/javascript" src = "script.js"></script>
    <link rel= "stylesheet" type = "text/css" href ="mystyle.css">
</head>
<body>
    <Table>
        <tr>
            <td class = "bingocell" id = 1>1</td>
            <td class = "bingocell" id = 2>2</td>
            <td class = "bingocell" id = 3>3</td>
            <td class = "bingocell" id = 4>4</td>
            <td class = "bingocell" id = 5>5</td>
        </tr>
       <tr>
            <td class = "bingocell" id = 6>1</td>
            <td class = "bingocell" id = 7>2</td>
            <td class = "bingocell" id = 8>3</td>
            <td class = "bingocell" id = 9>4</td>
            <td class = "bingocell" id = 10>5</td>
        </tr>
         <tr>
            <td class = "bingocell" id = 11>1</td>
            <td class = "bingocell" id = 12>2</td>
            <td class = "bingocell" id = 13>3</td>
            <td class = "bingocell" id = 14>4</td>
            <td class = "bingocell" id = 15>5</td>
        </tr>
         <tr>
            <td class = "bingocell" id = 16>1</td>
            <td class = "bingocell" id = 17>2</td>
            <td class = "bingocell" id = 18>3</td>
            <td class = "bingocell" id = 19>4</td>
            <td class = "bingocell" id = 20>5</td>
        </tr>
         <tr>
            <td class = "bingocell" id = 21>1</td>
            <td class = "bingocell" id = 22>2</td>
            <td class = "bingocell" id = 23>3</td>
            <td class = "bingocell" id = 24>4</td>
            <td class = "bingocell" id = 25>5</td>
        </tr>

    </Table>

<p>Click the button to display a random number between 1 and 78.</p>

<button id = "button" onclick = "myFunction()">Try it</button>

<p id="demo"></p>       



</body>
</html> 

Errors: ERROR: 'document' is not defined. [no-undef] document.getElementById("button").onclick = function(){myFunction()}; 4
ERROR: 'x' is assigned a value but never used. [no-unused-vars] var x = document.getElementById("demo"); 4
ERROR: 'document' is not defined. [no-undef] var x = document.getElementById("demo"); 6
ERROR: 'document' is not defined. [no-undef] document.getElementById("demo").innerHTML = random

Things to note: -File location of JS and CSS are in the exam same folder. -I never really learnt to write external JS so I don't understand differences between internal and external but what works internally doesn't seem to work externally and it's very frustrating.

1
Welcome to StackOverflow! Can you also provide the HTML for the code, and also more details regarding the exact error message? - Andreas
} is missing at the end of function(){myFunction(); - vrintle
Edit your question to add the HTML, don't add it in a comment. - RobG

1 Answers

0
votes

Problem solved Did 2 things: 1) moved the "

2) This part is a bit embarrassing but I think I should leave it here as a reminder. Copied the JS file, from a JS folder and have only been editing the one still within the JS folder but the one on the same folder has not been edited.

Thanks for the help guys!