-2
function Purchase() {
    document.getElementById("Button1").innerHTML = "Purchasing..."
    window.setTimeout(Purchase(), 30000)
    document.getElementById("Button1").innerHTML = "Done!"
}

Basically what I'm trying to do is make a fun little purchasing code test (I know it won't actually buy anything though).

Yousaf
  • 27,861
  • 6
  • 44
  • 69

1 Answers1

3
function Purchase() {
    document.getElementById("Button1").innerHTML = "Purchasing..."
    window.setTimeout(() => {
      document.getElementById("Button1").innerHTML = "Done!"
    }, 3000)  
}

is that what you need?

A couple of issues in your post: 30000 in milliseconds is 30 seconds

Also, you were calling Purchase() inside of your Purchase function making your function recursive and will make Purchase being executed over and over again

Also, setTimeout takes a function reference (not a function execution) as the first argument that will be executed after the interval you set as the second argument. Adding () in setTimeout(Purchase()) will cause the Purchase function to be executed straight away.

Kevin Amiranoff
  • 13,440
  • 11
  • 59
  • 90