I'm having trouble Listing 'em all


#1

Did you create a function called list?

var friends = {
bill: {
    firstName: "Bill",
    lastName: "Gates",
    number: "(206) 555-5555",
    address: ['405 Sherlock Road', 'Toronto', 'ON', '98052'] 
    },
steve: {
    firstName: "Steve",
    lastName: "Jobs",
    number: "(408) 456-7890",
    address: ['234 Watson Way', 'Minecraft', 'MC', '99999']
    }
};
function list () {
    for (var friends in object) {
        console.log(bill);
    }
}

Here is my function for in loop thingy
function list () {
    for (var friends in object) {
        console.log(bill);
    }
}


#2

Here are the errors:

function list() {
    for (var friends in object) { //The object is place holder text, you are supposed to replace it with a real object name.
                                  //And you have friends where you should be creating a new variable (that's what the var keyword does.
        console.log(bill); //Here you are asking the computer to console.log bill? You should be logging the variable that
                            //was made in the for loop parameters.
    }
}

Hope this helped you some!


#3

okay Ill try it out and message you if It worked


#4

here's an updated version of the code. I may or may not have used the hint to write the console.log

function list () {
for (var friends in object) {
console.log("Bill Gates", "Steve Jobs");
var friends = "Bill and Steve";
console.log(friends);
}
}
I'm still being asked if I created the list function


#5

Here, maybe this example would help:

var myObject = {
a: {
    firstName: "hi",
    lastName: "blah",
    },
b: {
    firstName: "Sean",
    lastName: "Chesswithsean",
    }
};

function list() {
    for (var variable in myObject) {
        console.log(variable);
    }
}
//This logs: a b

But with your code:

function list () {
for (var friends in object) { //object doesn't exist, you're supposed to replace it with a real object name, like I did above.
console.log("Bill Gates", "Steve Jobs"); //This ruins the point of the function, remove it.
var friends = "Bill and Steve"; //Now you're creating a new variable??
console.log(friends);
}
}

How does the for loop work? Instead of typing out the answers, the loop does it for us.

for(var a = 0; a < 5 a++) {
  console.log(a);
}
//I know you know this already, but notice that the computer does the work.

Please tell me if this helps.


#6

I'm still being asked if I created a function called list
Did you create a function called list?
function list () {
for (var friends in object) {
console.log(friends);
}
}


#7

In the first instruction:

01. Create a function list that takes a single parameter.

It tells you that it takes a parameter.. meaning an input variable. Therefore

function list () { /* The () should have something inside it */

#8

so is that why I keep being asked If i created the function?


#9

Yes, because you haven't completely finished your function in the first place as it requires an input variable.

EDIT: Actually....your loop looks a bit off. Check @chesswithsean's comment about the example. You need to loop in your object...but you're using it as an index......


#10

okay I added friends to the function and I'm still being asked if I asked if I created the function

function list (friends) {
for (var friends in object) {
console.log(friends);
}
}


#11

Check my comment above. I've changed it. Your loop looks off.


#12

got it I will, maybe part of the problem is the fact that I'm doing Javascript and other courses like HTML & CSS: part 1 and Java. The Java was what I wanted to learn first but I didn't know the diffrence


#13

and I spotted the problem with the function. I didn't write it properly. lol. but I'm still getting the same error message. what the heck is wrong?! Here's the function

var list = function (friends) {
for (var friends in object) {
console.log("Bill Gates", "Steve Jobs");
var myString = "I built Windows with A billion Dollars";
console.log(myString);
}
}

and here's what the hint says for writing functions

Here's how to create a function:

var list = function (friends) {
// Do something here
}


#14

Please I keep having the same problem but can't figure out why I always am having the same problem


#15

You still seem to have troubles with your loop. Your friends is THE object you are trying to loop through. But instead, you are using it as an index to loop through an object called object.

Secondly, you seem to have misunderstood this instruction:

03. In the loop, use console.log to print out the key. (For example, if you only have bill and steve as entries, list should just print out "bill" and "steve".)

What they mean by key is your index.
Your function should look something like this:

function random (object) {
    for (var key in object) {
        console.log(key);
    }
}

Your object is friends.


#16

Ohhhhhhhh........... now I understand


#17

well I fixed the first problem, here's what The error message says

Oops, try again. It looks like your list function isn't printing the right output.

output

Bill Steve
Hello Its me
Bill Steve
Hello Its me

code


#18

You need to print contact information, but you print your own output. That's why validation for this lesson was failed.


#19

oh okay I'll try to fix it and I'll come back here if i still can't figure it out.


#20

1 more thing. why is the code repeating its self like this

My friends are
bill steve
My friends are
bill steve

and I don't understand what the instructions want for me to log outside of my contacts in this exercise.