5. Finding that Special Someone


#1

This code print me SyntaxError: Unexpected token ILLEGAL

var bob = {
firstName: "Bob",
lastName: "Jones",
phoneNumber: "(650) 777-7777",
email: "bob.jones@example.com"
};

var mary = {
firstName: "Mary",
lastName: "Johnson",
phoneNumber: "(650) 888-8888",
email: "mary.johnson@example.com"
};

var contacts = [bob, mary];

function printPerson(person) {
console.log(person.firstName + " " + person.lastName);
}

function list() {
var contactsLength = contacts.length;
for (var i = 0; i < contactsLength; i++) {
printPerson(contacts[i]);
}
}

function search(lastName) {
var contactsLength = contacts.length;
for (var j = 0; j < contactsLength; j++) {
if (contacts[j].lastName === lastName) {
printPerson(contacts[j]);
}
}
};
search("Jones");

HELP


#2

The code worked fine for me.
Try removing this semicolon:

var bob = {
firstName: "Bob",
lastName: "Jones",
phoneNumber: "(650) 777-7777",
email: "bob.jones@example.com"
};

var mary = {
firstName: "Mary",
lastName: "Johnson",
phoneNumber: "(650) 888-8888",
email: "mary.johnson@example.com"
};

var contacts = [bob, mary];

function printPerson(person) {
console.log(person.firstName + " " + person.lastName);
}

function list() {
var contactsLength = contacts.length;
for (var i = 0; i < contactsLength; i++) {
printPerson(contacts[i]);
}
}

function search(lastName) {
var contactsLength = contacts.length;
for (var j = 0; j < contactsLength; j++) {
if (contacts[j].lastName === lastName) {
printPerson(contacts[j]);
}
}
};                    <- this one
search("Jones");

#3

i try, but results dont change, i am cry


#4

Strange, could you link the excersise and include your code like this:

 ```
 Your code here
 ```

#5

https://www.codecademy.com/en/courses/building-an-address-book/0/5?curriculum_id=506324b3a7dffd00020bf661#
var mary = {
firstName: "Mary",
lastName: "Johnson",
phoneNumber: "(650) 888-8888",
email: "mary.johnson@example.com"
};

var contacts = [bob, mary];

function printPerson(person) {
console.log(person.firstName + " " + person.lastName);
}

function list() {
	var contactsLength = contacts.length;
	for (var i = 0; i < contactsLength; i++) {
		printPerson(contacts[i]);
	}
}

var search = function(lastName) {
var contactsLength = contacts.length;
for(var j = 0; j < contactsLength; j++){
    if (lastName === contacts[j].lastName){
        printPerson(contacts[j]);
    }
}
};
search("Jones");

#6

It looks like you've removed the list called "bob".
Include this in your code, under the list mary:

var bob = {
    firstName: "Bob",
    lastName: "Jones",
    phoneNumber: "(650) 777-7777",
    email: "bob.jones@example.com"
};

#7

sorry, i just dont copy bob


#8
var bob = {
    firstName: "Bob",
    lastName: "Jones",
    phoneNumber: "(650) 777-7777",
    email: "bob.jones@example.com"
};

var mary = {
    firstName: "Mary",
    lastName: "Johnson",
    phoneNumber: "(650) 888-8888",
    email: "mary.johnson@example.com"
};

var contacts = [bob, mary];

function printPerson(person) {
    console.log(person.firstName + " " + person.lastName);
}

function list() {
	var contactsLength = contacts.length;
	for (var i = 0; i < contactsLength; i++) {
		printPerson(contacts[i]);
	}
}

var search = function(lastName) {
    var contactsLength = contacts.length;
    for(var j = 0; j < contactsLength; j++){
        if (lastName === contacts[j].lastName){
            printPerson(contacts[j]);
        }
    }
};
search("Jones");

#9

What exactly do you mean? I works now...


#10

it's funny, i remove all comments /**/ and this code works! :confused:


#11

Strange, it could have been an incomplete comment then.


#12

This code give me SyntaxError: Unexpected token ILLEGAL

var bob = {
    firstName: "Bob",
    lastName: "Jones",
    phoneNumber: "(650) 777-7777",
    email: "bob.jones@example.com"
};

var mary = {
    firstName: "Mary",
    lastName: "Johnson",
    phoneNumber: "(650) 888-8888",
    email: "mary.johnson@example.com"
};

var contacts = [bob, mary];

function printPerson(person) {
    console.log(person.firstName + " " + person.lastName);
}

function list() {
	var contactsLength = contacts.length;
	for (var i = 0; i < contactsLength; i++) {
		printPerson(contacts[i]);
	}
}

var search = function(lastName) {
    var contactsLength = contacts.length;
    for(var j = 0; j < contactsLength; j++){
        if (lastName === contacts[j].lastName){
            printPerson(contacts[j]);
        }
    }
};
search("Jones");

/*Create a search function
then call it passing "Jones"*/

/*Обнаружив, что-то специальное

Скажем, мы ищем кого-то в нашей адресной книге с определенной фамилией.

Мы можем сделать это с помощью метода для поиска массивов, называемый "линейный поиск". С его помощью, мы используем цикл, чтобы проверить через все элементы в массиве один за другим, пока мы не видим элемент, который мы хотим.

Мы можем применить линейный поиск, чтобы распечатать всех людей, которые имеют          определенную фамилию.*\

but if remove the comment this code works!


#13

Yes, the last comment isn't closed. If you put */ behind it the code will work fine.


#14

I mixed / and \ :weary: sorry


#15

No problem, have fun!


#16

2 posts were split to a new topic: It looks like you didn't log to the console


#17

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.