8. Victory - Improved Formatting?


#1

Hi,

I am trying to get my log to console to look like:

First Name: Steve
Last Name: Jobs
Number: (408) 555-5555
Address: 1 Infinite Loop
Cupertino, CA 95014

I cannot get a key within a key to display - I don't know how to reference it.

Here is the relevant part of my code:

var search = function (name) {
for (var key in friends) {
if ( friends[key].firstName === name) {
console.log(
"First Name: " + friends[key[firstName]]
//"Last Name: " + friends[lastName]
//"Number: " + friends[number]
//"Address: " + friends[address]
);
return friends[key];
}
}
}

list(friends);
search("Bill");


#2

it would be friends[key][firstName] in block notation
it could also be friends[key].firstName if you prefer dot notation :slightly_smiling: .

Hope that helps :sunny:


#3

Great that's working!

Now is there a way to display to the console.log to separate lines?

I've been trying the following:

console.log ("Text on line 1" \nline
"Text on line 2" \nline
"Text on line 3" \nline
"Text on line 4" );


#4

Just realized I can do it with multiple console.log();'s...

Is there a way to do it within a single console.log(); ?

For those interested, my code and output is shown below:

bill
steve
First Name: Bill
Last Name: Gates
Number: 333-444-5555
Address: One Microsoft Way
Redmond, WA 98052
{"firstName":"Bill","lastName":"Gates","number":"333-444-5555","address":["One Microsoft Way","Redmond","WA","98052"]}


#5

You were very close with that, this is how I would do what you are asking.

console.log ("Text on line 1\n" +
"Text on line 2\n" +
"Text on line 3\n" +
"Text on line 4" );

:slightly_smiling:


#6

Awesome thanks edwin!