Contact list 7 bug


#1
var friends = {};
friends.bill={
    firstName:'bill',
    lastName:'zvccdsavd',
    number:42543254325,
    address: ['piter', 'burg']
    };
friends.steve={
    firstName:'steve',
    lastName:'dasfdsafdasfsda',
    number:564365365,
    address: ['moscow', 'russia']
    };
 
 /*   
var list = function(friends) {
        
for (var key in friends){
    console.log(key);
    } ; 
    
    };   
*/
    
var search =function(name) {
for (var key in friends){
  //  console.log(key);
    if (friends[key].firstName === name) {
        var zzz="adress: "+friends[key].address+" number: "+friends[key].number
       console.log(zzz);
       return zzz;
        };
    
    } ;   
    
    } ;  
 search("steve");

I do not understand what the problem is! The function returns the contact well


#2

May I ask what the error message you're receiving is?

Also check this if statement.

if (friends[key].firstName === name) {
        var zzz="adress: "+friends[key].address+" number: "+friends[key].number
       console.log(zzz);
       return zzz;

        };
         ^

Remember you can't have a semi-colon after a if statement or it will error.


#3
var friends = {};
friends.bill={
    firstName:'bill',
    lastName:'zvccdsavd',
    number:42543254325,
    address: ['piter', 'burg']
    }
friends.steve={
    firstName:'steve',
    lastName:'dasfdsafdasfsda',
    number:564365365,
    address: ['moscow', 'russia']
    }
 
 /*   
var list = function(friends) {
        
for (var key in friends){
    console.log(key);
    } ; 
    
    };   
*/
    
var search =function(name) {
for (var key in friends){
  //  console.log(key);
    if (friends[key].firstName === name) {
        var zzz="adress: "+friends[key].address+" number: "+friends[key].number
       console.log(zzz);
       return zzz;
        }
    
    }    
    
    }   
 search("steve");

I corrected code, but the error appears vseravno—

Oops, try again. 

It looks like your search function doesn't return contact information for Steve.

#4
var friends = {};
friends.bill={
    firstName:'bill',
    lastName:'zvccdsavd',
    number:42543254325,
    address: ['piter', 'burg']
    }
friends.steve={
    firstName:'steve',
    lastName:'dasfdsafdasfsda',
    number:564365365,
    address: ['moscow', 'russia']
    }
 
   
var list = function(friends) {
        
for (var key in friends){
    console.log(key);
    }  
    
    }  

    
var search =function(name) {
for (var key in friends){
  //  console.log(key);
    if (friends[key].firstName === name) {
       var zzz="adress: "+friends[key].address+" number: "+friends[key].number
       console.log(zzz);
       return zzz;
        }
    
    }    
    
    }   
 search("steve");

Error ----- Oops, try again. It looks like your search function doesn't return contact information for Steve.


#5

when you define your search function you put "=function"... put a space after the = and that should help.


#6

I'm not too sure about this, but I think it has something to do with the for loop inside your 'search' function. When you wrote this loop before, you wrote the exact same thing as before and it worked. But the problem is that 'friends' in for (var key in friends) is a parameter of the function 'list'.

But 'friends' isn't a parameter for the 'search' function, so 'friends' in the second for loop would be undefined.


#7

Sorry, please ignore the thing about 'friends'. Anyway, I have completed this and I think that the reason this isn't working for you is because you added var zzz="adress: "+friends[key].address+" number: "+friends[key].number

Try deleted that, and changing the console.log(); and return. Your code should work now.