Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8954687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:21:55+00:00 2026-06-15T14:21:55+00:00

I get a syntax error: unexpected identifier at line 22. I’ve been over and

  • 0

I get a syntax error: unexpected identifier at line 22. I’ve been over and over this code, and I can’t for the life of me figure out what’s wrong. It’s a code to determine the shortest route from one node to another.

"use strict"
function findpath(G,si,di){
    //G is an array of nodes (with id, lat, lon)
    var cvi = si;
    var P=[si];
    var C=[0,P];
    var M=[C];
    var O=[];
    var ctr=0;
    var done = false;
    var reached = false;
    var best = undefined;


    while(!done){
        ctr++;
        if( ctr > 100 ){
            alert("Sorry, can't find the destination.");
            return P;
        }

        for (int i=0;i<M.length;++i){
            var last = M[i[1]].length;
            var v = M[i[1[last]]];

            //select a random neighbor...
            if( v.N.length === 0 ){
                alert("Wat?");
                return [];
            }
            else if( v.N.length === 1 ){
                break;
            }
            else if( v === di ){
                break;
            }
            else {
                for (int j=0;j<v.N.length;++j){
                    var temp = M[i];
                    O.push(temp[1].push(v.N[j]));
                    var dist = distance(v.lat,v.lon,v.N[j].lat,v.N[j].lon);
                    var temp2 = O.length-1;
                    O[temp2[0]]+=dist;
                    if (v.N[j]===di){
                        reached = true;
                        if (best === undefined){
                            console.log("ASSIGN");
                            best = O[temp2];
                        }
                        else {
                            if (O[temp2[0]]<best[0]) {
                                best = O[temp2];
                            }
                        }
                    }
                }
            }
        }
        M = O;
        var any = false;
        for (int i=0;i<M.length;++i) {
            if (M[i[0]]<best[0]) {
                any = true;
            }
        }
        if (!any) {
            done = true;
        }
    }

    //return the path
    return best[1];
}

function distance(x1,y1,x2,y2){
    return Math.sqrt(Math.pow((x2-x1),2)+Math.pow((y2-y1),2));
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T14:21:56+00:00Added an answer on June 15, 2026 at 2:21 pm

    This:

        for (int i=0;i<M.length;++i){
    

    shouldn’t have int. It should be var.

        for (var i=0;i<M.length;++i){
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can't figure out why I get this error: Parse error: syntax error, unexpected
I keep getting the Syntax Error: Unexpected identifier JS error with this code: function
See also SO 1664677 I get this error 2: Syntax error: ( unexpected when
In the following script I get an error: syntax error: unexpected end of file
I get an error that says Parse error: syntax error, unexpected T_PRIVATE in E:\PortableApps\xampp\htdocs\SN\AC\ACclass.php
In running this on index.html, I get the following error: Uncaught SyntaxError: Unexpected token
I get this error when I run the application Incorrect syntax near 12 ,
I'm reluctant to ask this but I can't figure it out. When I run
./chkf: line 30: syntax error near unexpected token `elif' '/chkf: line 30: `elif [
I get a syntax error in Python 2.7.3 like so: [s += 'Orig' for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.