最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - "Expected , but found }" Error - Stack Overflow

programmeradmin2浏览0评论

Just a quick debugging question. I'm new to Javascript, and I'm creating a scheduling program with a group. My job is to take the user-inputted classes and output arrays of the required and optional classes. (each array element is a 1-element array containing a class object, except for when there are multiple sections of a class). I agree that returning these 2d arrays is a non-efficient way to do this, but it's what the people working on creating all possible schedules want.

I'm getting a syntax error that I don't understand, and I was wondering if anyone can spot what's causing it. Thanks in advance if you can. Here's the first part of my code where it pops up.

for(var m = 0; m < numClasses; m++){
    $.getJSON("/?term=4540&subject="+optCourses[m].subject, function(result) {
        $(result).each(function (index, item) {
        if (item.start_time > startTime) {
            if (item.end_time === endTime){
            if (item.catalog_num === optCourses[m].courseNumber){

                var coursject = {
                    title: item.title,
                    professor: item.instructor.name,
                    catalog_num: item.catalog_num,
                    section: item.section,
                    subject: item.subject,
                meeting_days: item.meeting_days,
                start_time: item.start_time,
                end_time: item.start_time
                    };
                OptclassList[i] = coursject;
                console.log(OptclassList[i]);
                i++;
                                                                    }
                                            }
                                            }        
                                            }
     } //**ERROR: Expected , but found }**
                                    }

    var OptcourseArray = [];   // **ERROR: Expected , but found var**       
    for(var j = 0; j < numOptCourses; j++){
        var catNum = optCouses[j].courseNumber;
        for(var h = 0; h<OptclassList.length; h++){
                var myArray = [];
                if (OptclassList[h].catalog_num == catNum){
                    myArray.push(OptclassList[h]);
                }
        }   
    OptcourseArray.push(myArray);
    }

Just a quick debugging question. I'm new to Javascript, and I'm creating a scheduling program with a group. My job is to take the user-inputted classes and output arrays of the required and optional classes. (each array element is a 1-element array containing a class object, except for when there are multiple sections of a class). I agree that returning these 2d arrays is a non-efficient way to do this, but it's what the people working on creating all possible schedules want.

I'm getting a syntax error that I don't understand, and I was wondering if anyone can spot what's causing it. Thanks in advance if you can. Here's the first part of my code where it pops up.

for(var m = 0; m < numClasses; m++){
    $.getJSON("http://vazzak2.ci.northwestern.edu/courses/?term=4540&subject="+optCourses[m].subject, function(result) {
        $(result).each(function (index, item) {
        if (item.start_time > startTime) {
            if (item.end_time === endTime){
            if (item.catalog_num === optCourses[m].courseNumber){

                var coursject = {
                    title: item.title,
                    professor: item.instructor.name,
                    catalog_num: item.catalog_num,
                    section: item.section,
                    subject: item.subject,
                meeting_days: item.meeting_days,
                start_time: item.start_time,
                end_time: item.start_time
                    };
                OptclassList[i] = coursject;
                console.log(OptclassList[i]);
                i++;
                                                                    }
                                            }
                                            }        
                                            }
     } //**ERROR: Expected , but found }**
                                    }

    var OptcourseArray = [];   // **ERROR: Expected , but found var**       
    for(var j = 0; j < numOptCourses; j++){
        var catNum = optCouses[j].courseNumber;
        for(var h = 0; h<OptclassList.length; h++){
                var myArray = [];
                if (OptclassList[h].catalog_num == catNum){
                    myArray.push(OptclassList[h]);
                }
        }   
    OptcourseArray.push(myArray);
    }
Share asked Jun 2, 2014 at 2:22 singmotorsingmotor 4,18013 gold badges55 silver badges82 bronze badges 3
  • 3 First suggestion: try reformatting. I would guess that your problem would be much easier to find. – Andrew Eisenberg Commented Jun 2, 2014 at 2:23
  • 1 You're missing a ) ($.getJSON is a function call) – p.s.w.g Commented Jun 2, 2014 at 2:24
  • 1 Actually, 2 parens: one on the //**ERROR: Expected , but found }** line and one on the line before. – Andrew Eisenberg Commented Jun 2, 2014 at 2:26
Add a ment  | 

1 Answer 1

Reset to default 1

there is an issue on line 26 of your code , the right way is :

for(var m = 0; m < numClasses; m++){
    $.getJSON("http://vazzak2.ci.northwestern.edu/courses/?term=4540&subject="+optCourses[m].subject, function(result) {
        $(result).each(function (index, item) {
        if (item.start_time > startTime) {
            if (item.end_time === endTime){
            if (item.catalog_num === optCourses[m].courseNumber){

                var coursject = {
                    title: item.title,
                    professor: item.instructor.name,
                    catalog_num: item.catalog_num,
                    section: item.section,
                    subject: item.subject,
                meeting_days: item.meeting_days,
                start_time: item.start_time,
                end_time: item.start_time
                    };
                OptclassList[i] = coursject;
                console.log(OptclassList[i]);
                i++;
                                                                    }
                                            }
                                            }        
                                            }
     ) //**ERROR: Expected , but found }**



    var OptcourseArray = [];   // **ERROR: Expected , but found var**       
    for(var j = 0; j < numOptCourses; j++){
        var catNum = optCouses[j].courseNumber;
        for(var h = 0; h<OptclassList.length; h++){
                var myArray = [];
                if (OptclassList[h].catalog_num == catNum){
                    myArray.push(OptclassList[h]);
                }
        }   
    OptcourseArray.push(myArray);
    }
发布评论

评论列表(0)

  1. 暂无评论