user1644644
user1644644

Reputation: 123

Uncaught SyntaxError: Unexpected token function

I keep getting the "unexpected token function" error when trying to run the following code. The error appears at the if(highPriority(priority)) { line. I appreciate any help, thanks.

$(function(){
  $("input[name=task]").focus();

  $("body").on("click","#add",function(){

    var task = $("input[name=task]").val();
    var priority = $(this).parent().children("input[name=priority]"); 
    var doneSpan = '<span class="done">Done</span>';  

    if(highPriorityChecked(priority)) {

    $("#todo").prepend("<p class='row high-priority'>" + task + doneSpan + "</p");

  } else {$("#todo").append("<p class='row normal-priority'>" + task + doneSpan + "</p");
    };

      resetForm();    

      doneList();  

});

}

function highPriorityChecked(priority){
  return $("input[name=priority]").is(":checked");
};

function doneList(){ 
    $("#todo").on("click",".done",function(){
    var row = $(this).parent().detach();
    $("#done").prepend(row).remove(doneSpan);
    });
}

function buildRow(task, priority) {
  var row = '<div class="row item ' + priority + '">' + task;
  var doneSpan = '<span class="done">Done</span>';
  return row + doneSpan + "</div>";
};

function resetForm() {
  $("input[name=task]").val("").focus();
  $("input[name=priority]").removeAttr("checked");
 };

Upvotes: 12

Views: 55262

Answers (1)

Day
Day

Reputation: 9693

adeno gave the right answer in his comment

You didn't close the document.ready function properly, it's just closed by a single curly bracket.

He suggested you might have notice if you had formatted your code properly. But we can do better than that.

In general, when you get a syntax error in JavaScript, try running the entire script through jslint. This may help point you at the cause of the error.

Upvotes: 12

Related Questions