Profile Lookup Excercise : SyntaxError: Unexpected token ;?

Profile Lookup Excercise : SyntaxError: Unexpected token ;?
0

#1

So i’ve made it this far, but this latest error is driving me NUTS! (in chrome) I cant see any extra or missing semi colons… And in I.e. i get a different error! (expceted a WHILE… go figure?) Yet when i paste this code into Visual studio it seems to work just fine?

any help? i’d like to ‘complete’ the task and move to the next, but I’m completely lost about this semi colon…?? Here’s my code:

//Setup
var contacts = [
    {
        "firstName": "Akira",
        "lastName": "Laine",
        "number": "0543236543",
        "likes": ["Pizza", "Coding", "Brownie Points"]
    },
    {
        "firstName": "Harry",
        "lastName": "Potter",
        "number": "0994372684",
        "likes": ["Hogwarts", "Magic", "Hagrid"]
    },
    {
        "firstName": "Sherlock",
        "lastName": "Holmes",
        "number": "0487345643",
        "likes": ["Intriguing Cases", "Violin"]
    },
    {
        "firstName": "Kristian",
        "lastName": "Vos",
        "number": "unknown",
        "likes": ["Javascript", "Gaming", "Foxes"]
    }
];


function lookUpProfile(firstName, prop) {
    // Only change code below this line

    var matched = false;
    var i = 0;
    do {

        if (firstName === contacts[i].firstName) {

            matched = true;
                        
            if (contacts[i][prop]) { return contacts[i][prop]; }
          
            else { return "No such property"; }
           }
        
        else {
            i++;
            if (i  === contacts.length) { return "No such contact"; }
        }


    }while (!matched && i < contacts.length);
    // Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes");

#2

Your code is correct but somehow the blank spaces are messing something up. Btw Firefox shows this error: missing while after do-loop but Chrome shows Unexpected token. Weird.

Anyway, try removing the blank lines:

  • after do {,
  • before } while (...)
  • before matched = true

#3

do you mean the space between do and { ? i’ve tried that… doesnt seem to make any difference? this one has me stuck completely… could it be that this excercise doesnt want me to use a ‘do/while’ statement?


#4

You should remove everything I listed.

Here’s a part of the code you posted. Remove all of those blank lines that are marked red below.

    var matched = false;
    var i = 0;
    do {
-                                                     
        if (firstName === contacts[i].firstName) {
-                                                     
            matched = true;
                        
            if (contacts[i][prop]) { return contacts[i][prop]; }
          
            else { return "No such property"; }
           }
-                                            
        else {
            i++;
            if (i  === contacts.length) { return "No such contact"; }
        }
-                                            
-                                            
    }while (!matched && i < contacts.length);
    // Only change code above this line

Using do-while loops are fine, but it looks like the editor has trouble dealing with those.


#5

omg! that fixed it thank you! I’ve literally spent HOURS just trying to get past that ; error and without a proper debugger i was losing my mind! thank you so much! you tought me a new lesson!!


#6

Maybe some invisible characters were present. I have had that happen when copying/pasting from a word document or some other non-editor source. I have pulled my hair out trying to figure these kind of errors out.


#7

It doesn’t look like it. If you removed the blank lines in the editor so that the code works, you can revert it to a broken state by re-inserting blank lines. (And that’s why I prefer having visual feedback on spaces on my code editor)