On off loop system on javascript [duplicate]

Hi guys my function is not working..

function onoff() {
  if(a != true){
    var a = true
    alert("System is on")
  } else if(a == true) {
    var a = false
    alert("System is off")
  }
}

And this is the html

<button type="button" id="demo" onclick="onoff()">Click Me!</button>

I couldnt figure it out how can i do it.
Thx for your helping <33