Jump to content
Sign in to follow this  
brooke_theperson

How to add strings to an array that is a parameter of a function?

Recommended Posts

So I am working on a simple client database type program. I have a clients array that stores new clients that all have a first name, last name, phone number, etc... I also want the user to be able to add notes about their clients' family. So, one of the parameters of the client function is an array called familyNotes. Here is the code for this:

function client(firstName, lastName, phoneNumber, address, hireDate, frequency, cost, entry, familyNotes) {
    this.firstName = firstName;
    this.lastName = lastName;
    this.phoneNumber = phoneNumber;
    this.address = address;
    this.hireDate = hireDate;
    this.frequency = frequency;
    this.cost = cost;
    this.entry = entry;
    this.familyNotes - familyNotes;
}
var laura = new client("laura", "simmerman", "1111111111", "laura rd", "01/01/01", "weekly", "100", "garage-1111");
var jana = new client("jana", "simmerman", "2222222222", "jana rd", "01/01/01", "weekly", "100", "garage-2222");
var clients = [laura, jana];
	

However, I do not know if the familyNotes array is working properly. I have a function that prompts the user to add a note about the family of a client, then adds the note to the array. Here is the code for this function:

function addFamilyNotes(i) {
    var note = prompt("Add a note about the family: ");
    document.getElementById("familyNotes").innerHTML += "<li>" + note + "</li>";
    clients[i].familyNotes.push(note);
}
	

I later have a function that is supposed to alert the length of the familyNotes array, however it doesn't alert anything currently. Here is the code: 

function familyNotesAlert(i) {
    alert(clients[i].familyNotes.length);
}
	

Does anyone know what I am doing wrong? Why is the alert not showing, and is anything actually being added to the familyNotes array?

Edited by brooke_theperson
Code needed to be formatted properly

Share this post


Link to post
Share on other sites

You should check your developer console for error messages, I'm sure you'll see an error message that clients.familyNotes is undefined.  Check your assignment statement when you set that value.

Share this post


Link to post
Share on other sites

Open your browser's developer tools and go to the Console tab.  In various browsers you might use F12 or Ctrl-Shift-I to open them, or find it in a menu somewhere.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...