Search code examples
javascriptfunctionexpressionexpectations

Semicolon, Expectations, and (end)


I was proofreading this function with JSFiddle, and it said there is a missing semicolon on the second line, however, I cannot determine where it would go.

function debtSpiral() {
  var debtID = setInterval(debtIncrease() { //Sets variable for loop stopping later
    debt = (debt * 0.10) + debt; //Increases debt by ten percent...
    document.getElementById("debt").innerHTML = "You owe " + debt + " click(s)"; //Display debt
  }, 60000); //...per minute
  if (debt < 1) { //If you owe less than 1 click
    clearInterval(debtID); //Stop 
  }
}

In addition, JSFiddle is reporting that it "expected an assignment or function call and instead saw an expression" on the fifth line. Can you explain this and how to fix it?

Lastly, why would I need to use (end) on the ninth line?

The fiddle in question (press "JSHint" to see the errors)


Solution

  • This is just a syntax error:

    var debtID = setInterval(debtIncrease() { //Sets variable for loop stopping later
    

    I don't know what to advise as a replacement as it really just doesn't make sense. The setInterval() function takes either a string (don't do that) or a function reference as its first parameter. Your code is neither of those; it's not really anything. It's a function call followed by a block, which in this context is not valid.

    Maybe you meant (as a comment on this answer suggests)

    var debtID = setInterval(function debtIncrease() { // ...