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.
}is missing at the end offunction(){myFunction();- vrintle