Contact list: adding properties


I actually did this one right, but i also tried a different approach and i don't understand why it's not right.
Is this possible to do? Is my code wrong, or it is in fact a wrong approach?

arrayData = ["firstName", "lastName", "number"];

var friends = {
    bill: {["Bill", "Gates", "00351916493636"]},  
    steve: {["Steve", "Jobs", "213886750"]}


To determine the correctness of something you gotta first establish what it's meant to do. "right" doesn't have any meaning before you do that!



i also did this way, and got it right

var friends = {
    bill: {
            firstName: "Bill",
            lastName: "Gates",
            number: "00351916493636"
    steve: {
            firstName: "Steve",
            lastName: "Jobs",
            number: "213886750"

But wanted to try in a different way to see if i was understanding everything. The first code that i posted, isn't a alternative way to do it?


That still depends on what "it" is!

It's a bit like if I ask you whether my painting looks like what it's supposed to look like.. But I'm not telling you what it's supposed to look like so you just can't tell if it does

What is the purpose of what you wrote?

And also, can you think of testing whether that purpose is being met? If not, where's the trouble in that, what in particular are you missing to do that?


i don't understand what you mean.
this was the exercise

i'm just asking if the first code is an alternative code to the one that was accepted


Was it also accepted? If so, then do you have reason to believe it's not doing the same thing?

If it wasn't accepted, then surely you have the answer, right? Or do you have reason to think that it still does the same thing, and if so, what's that reason?

I can't give a straight answer to what you're asking, because the question doesn't add up! I could try to correct the question, but then I'm both asking and answering and who then am I talking to, right?

And, most likely if you ask what you really mean, if you establish what it is you want to know, you can probably even answer that yourself. Or if you can't, then you'll still have something that can be answered by somebody else. Either way, the question needs to be better defined!


If what you really mean is: I have a syntax error, is my code correct?

Then the answer is no, your code isn't even code, so you don't have something that's either correct or wrong, you don't have a program to be considered


Being a begginer, it's normal to have a code not accepted by some syntax error. That's what i'm asking, if the code has any sintax error and that is the reason why it's not accepted.

instead of writing firstname: "Bill" inside the object, is it possible to define an array with firstname,lastname and then calling that array inside the object?


What would calling an array do?


ok, nevermind.
I appreciate your answers but that kind of answer doesn't really help clarifying things to someone trying to learn

thank you


I have to start by straightening out the question.

Writing code is to describe a series of events, right?
So when you describe those events in English, it has to be something you can carry out.

You must start with intention to do something. Otherwise you try to do something, but you don't know what, and you expect it to turn into something, but don't know what either.

Being a beginner doesn't change any of that.


ok, last try

If i had 40 names it the contact list i would have to do 40 times

 bill: {
            firstName: "Bill",
            lastName: "Gates",
            number: "00351916493636"

i was just trying to avoid writing for every new entry the name of the properties. I'm asking if it's possible to build a variable, an array, or something that defines the names of the properties so i only have to write the values of each propertie


This isn't a response to your last reply, working on that next.

To call something means to start executing that something, and then when it has finished, to return back to immediately after where the call happened.

This is something you would do with a function. You would for example put 3 and 7 as arguments, then call +, and when it's done, you would have obtained 11

This isn't something that makes sense to do for an array. See the problem? We can't continue from the wish to call an array. We have to fix that description first.

Maybe you meant something else, but you must be careful to describe things accurately, even if that means typing a whole lot more in order to describe it in a way that you know how!


ok, that is an answer that helps to clarify :stuck_out_tongue:


Much better.

So this address book is data, yes? It would be reasonable to read it from file or something, having it hard-coded into the program is actually a little strange.

You could definitely put the values "Bill", "Gates", "00351916493636" into an array, and then have some code which assumes that the first value is the first name, then last then number - and use that to generate the same data as you otherwise would be typing the object literals for. You'd be trading object literals for array literals (not incredibly significant, but yes, you definitely can and it would be a worthy thing to make happen for practice if for no other reason)

Storing three values in order is something you can do with an array.
If you have 40 such arrays, then you could put those arrays in an array as well.
I believe you're familiar with how to write array literals.


ok...thank you for your reply.
Have to leave now, but will try that later.

again...thank you


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