1. Welcome to the Brawl website! Feel free to look around our forums. Join our growing community by typing /register in-game!

Your very own address book!

Discussion in 'Off Topic' started by maxwellj02, Nov 12, 2013.

Thread Status:
Please be aware that this thread is more than 30 days old. Do not post unless the topic can still be discussed. Read more...
  1. maxwellj02

    maxwellj02 Well-Known Member

    Joined:
    Aug 4, 2013
    Messages:
    939
    Ratings:
    +163
    copy the code below and go to repl.it/languages/JavaScript

    Code:
    var contacts = new Array();
    
    function printPerson(person)
    {
      console.log("Name:"+" "+person.firstName+" "+person.lastName+"  "+"Phone number:"+" "+person.phoneNumber+"  "+"Email:"+" "+person.email);
    }
    
    function list()
    {
        var contactsLength=contacts.length;
     
        console.log("If you would like to know more about any entry, do 'search(firstName)'(firstName eaten by quotes)");
     
        console.log("Names:");
     
        for (var i=0; i<contactsLength; i++)
        {
            console.log(contacts[i].firstName+" "+contacts[i].lastName);
        }
    }
    
    function search(firstName)
    {
        var contactsLength=contacts.length;
        for (var i=0; i<contactsLength; i++)
        {
            if (contacts[i].firstName==firstName)
            {
                printPerson(contacts[i]);
            }
        }
    }
    
    function add(firstName,lastName,phoneNumber,email)
    {
        this.firstName=firstName;
        this.lastName=lastName;
        this.phoneNumber=phoneNumber;
        this.email=email;
        contacts.push(this);
    }
    
    //List contacts here. [Syntax: var (shortname for person)=new add("firstName","lastName","phoneNumber","email")]
    
    //Call functions here. {[printPerson(variable name);],[list();],[search(lastName);]}
    
    
    
    Step 1. find
    Code:
    //List contacts here.
    Step 2. go to the line under that, then type
    Code:
    var {shortname for person}=new add("{firstName}","{lastName}","{phoneNumber}","{email}"
    (Put own parameters in { } braces.
    Step 3. repeat step 2 as much as you want.
    Step 4. list/search/printPerson as much as you want! If you want to list all entries, type
    Code:
    list();
    . If you want to search for someone, type
    Code:
    search({firstName});
    . If you want to printPerson them, do
    Code:
    printPerson({shortname for person});
    This is my first real JavaScript program since I started taking online classes Saturday. To make an entry, you type
    Code:
    var (shortname for person)=new add("firstName","lastName","phoneNumber","email"
    Functions:
    • printPerson: This function will print a parameter given with extra text, and the parameter is the thing in between the parentheses. In this case the parameter will be the (shortname for person) what you called your variable.
    • list(): This function takes no parameters. It will print out all the entries in the address book.
    • search: This function will search through all the entries and match the firstName property. If it matches, it w/ill print it out with extra text.
    • add("firstName","lastName","phoneNumber","email"): This function will take the inputs, exactly as written (YOU NEED THE QUOTES), and feed them into a variable.
    If there are any bugs, let me know!
     
    #1 maxwellj02, Nov 12, 2013
    Last edited: Nov 13, 2013
  2. Pegleg98

    Pegleg98 Well-Known Member

    Joined:
    Aug 8, 2013
    Messages:
    1,094
    Ratings:
    +535
    This is all very confusing. I wish I could just code by typing sentences in english.
     
  3. Mokolee

    Mokolee Well-Known Member

    Joined:
    Aug 25, 2013
    Messages:
    4,767
    Ratings:
    +1,470
    Yeah can you please tell us how do to this step by step?
     
  4. Shayne

    Shayne Well-Known Member

    Joined:
    Aug 17, 2013
    Messages:
    1,430
    Ratings:
    +643
    r u tryin to give me verisus???????????????
     
  5. maxwellj02

    maxwellj02 Well-Known Member

    Joined:
    Aug 4, 2013
    Messages:
    939
    Ratings:
    +163
    Code is very confusing.
    wut
    Give me the steps you want. Then I can help.
     
  6. Mokolee

    Mokolee Well-Known Member

    Joined:
    Aug 25, 2013
    Messages:
    4,767
    Ratings:
    +1,470
    Ok I want good and clear steps that help us do this thing which seems pointless. Seriously, is this a trap?
     
  7. __Quay__

    __Quay__ Well-Known Member

    Joined:
    Aug 6, 2013
    Messages:
    1,258
    Ratings:
    +524
    Discord:
    Quay#5263
    how we know it not a vires
     
  8. Shayne

    Shayne Well-Known Member

    Joined:
    Aug 17, 2013
    Messages:
    1,430
    Ratings:
    +643
    he tryin rat me
     
  9. Javed

    Javed Well-Known Member

    Joined:
    Aug 6, 2013
    Messages:
    1,867
    Ratings:
    +370
    Is not vires
     
  10. maxwellj02

    maxwellj02 Well-Known Member

    Joined:
    Aug 4, 2013
    Messages:
    939
    Ratings:
    +163
    It is not a virus.
    Step 1. find
    Code:
    //List contacts here.
    Step 2. go to the line under that, then type
    Code:
    var {shortname for person}=new add("{firstName}","{lastName}","{phoneNumber}","{email}"
    (Put own parameters in { } braces.
    Step 3. repeat step 2 as much as you want.
    Step 4. list/search/printPerson as much as you want! If you want to list all entries, type
    Code:
    list();
    . If you want to search for someone, type
    Code:
    search({firstName});
    . If you want to printPerson them, do
    Code:
    printPerson({shortname for person});
     
  11. Mokolee

    Mokolee Well-Known Member

    Joined:
    Aug 25, 2013
    Messages:
    4,767
    Ratings:
    +1,470
    And what is this for exactly? What's the point of doing this?
     
  12. Javed

    Javed Well-Known Member

    Joined:
    Aug 6, 2013
    Messages:
    1,867
    Ratings:
    +370
    It does nothing. It is a comment. a "//" before a line means it is exempt from the code.
     
Loading...
Similar Threads Forum Date
How is everyone doing? MC-WarZ Jan 28, 2024
Where is every1? Discussion May 16, 2022
How is everyone Raid Dec 31, 2021
Heavy and Archer at the end of everything Capture the Flag Nov 26, 2021
25% Off Everything! ☘ St. Patrick's Sale & Limited Items ☘ News & Announcements Mar 16, 2021
Thread Status:
Please be aware that this thread is more than 30 days old. Do not post unless the topic can still be discussed. Read more...