Output for search for a friend


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>

<In what way does your code behave incorrectly? Include ALL error messages.>

MY OUTPUT IS RIGHT. ALTHOUGH MY DOUBT IS WHY THE LINE OF CODE console.log("$$$$$"); is not printed?. DOES THIS MEAN AFTER return STATEMENT FUNCTION IS TERMINATED?..my output is as follows:

bill
steve
{ firstName: ‘Bill’,
lastName: ‘Mosby’,
number: ‘+91 8451’,
address: [ ‘milp’, ‘sec25’, ‘nerul’, 40072 ] }


```

var friends=new Object();

friends.bill={};
friends[“steve”]={};
friends.bill.firstName=“Bill”;
friends.bill.lastName=“Mosby”;
friends.bill.number="+91 8451";
friends.steve.firstName=“Steve”;
friends.steve.lastName=“Stinson”;
friends.steve.number="+912480";
friends.bill.address=[“milp”,“sec25”, “nerul”,40072];
friends.steve.address=[“saist”, “sec 34”, “vash”, 40125];
var list=function(friends){
for(var x in friends){
console.log(x);
console.log("=======")
}
};
var search= function(name){
for (var z in friends){
if (friends[z].firstName===name){
console.log(friends[z]);
console.log("*******")
return friends[z];
console.log("$$$$$$$$$$$");
}
else {
console.log(“match not found”);
}
}
};
list(friends);
var y=search(“Bill”);
console.log(“ALL THAT IS DISPLAYED NOW IS COURSE CHECKER”)

<do not remove the three backticks above>

#2

@coreace10979

I think your console.log needs a semicolon.

which is stopping the rest of the script from being executed.


#3

done. but does not change anything.


#4

@coreace10979

Try putting this line

before your return statement see what it does


#5

@miniapple8888 it gives the following output:
bill
steve
{ firstName: ‘Bill’,
lastName: ‘Mosby’,
number: ‘+91 8451’,
address: [ ‘milp’, ‘sec25’, ‘nerul’, 40072 ] }
**
$$$$$$$$$$$


#6

but it does not print $$$$$$ when the console.log("$$$") statement is written after return statement


#7

@coreace10979

console.log and return functions are different. More information here