0

output = document.getElementById('output');

function off() {
  output.innerText = 'turning off';
  wait(3000);
  output.innerText = '/n off';
}
<!DOCTYPE html>
<html>

<head>
  <script src="script.js"></script>
</head>

<body>
  <button onclick="off()">press me to start</button>
  <p id="output">Fun game</p>
</body>

</html>

I want it to show the texts in the output but nothing happens. Is there any solution for this problem?

Peter Krebs
  • 3,831
  • 2
  • 15
  • 29
sewqq
  • 9
  • 2
  • 1
    Try moving your script to the end of the body. Since it's in the head, `output = document.getElementById('output');` won't find the element since it doesn't exist yet – j08691 Mar 06 '23 at 16:47
  • 3
    Where is your `wait` function? – Marc Mar 06 '23 at 16:47
  • 1
    what is wait function? culprit :) – user1844933 Mar 06 '23 at 16:49
  • 2
    Hi! I made your code a snippet that can run directly in StackOverflow. It outputs this error if you run it: "Uncaught ReferenceError: wait is not defined". wait does not exist in JavaScript. Just search the internet how to delay a function in JavaScript. Also please [take the tour](https://stackoverflow.com/tour) – Peter Krebs Mar 06 '23 at 16:49
  • 1
    It sounds like there are *multiple* problems here. In the original code posted by the OP, I'd expect the error produced to simply be a duplicate of [this](https://stackoverflow.com/q/14028959/328193). Even after correcting that, there are certainly *more* problems. The OP should take this opportunity to start using the browser's debugging tools to identify specific error messages and other specific problems. – David Mar 06 '23 at 16:55

0 Answers0