Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Regular Coder
    Join Date
    Nov 2010
    Location
    canada
    Posts
    131
    Thanks
    51
    Thanked 0 Times in 0 Posts

    Writing Table Cells and Switch Statements - javascript

    Writing Table Cells and Switch Statements

    I am to create a function and purpose is to write blank tables cells to make up horizontal bar. function will have 2 parameters=(partyType and percent

    partyType parameter stores variables of D,R,I,G or L

    percent parameter store percentage rounded to nearest integer

    so I am to make a switch and break statements /commands

    then have to create a For Loop in counter variable goes up from 1 through value of parmeter increments of 1

    heres the code I created for this one
    Code:
         function createBar(partyType,percent){ // script element to create blank cells
    switch(partyType) {
    case "D": document.write("<td class='dem'></td>");
    break;
    case "E": document.write("<td class='rep'></td>");
    break;
    case "I": document.write("<td class='ind'></td>");
    break;
    case "G": document.write("<td class='green'></td>");
    break;
    case "L": document.write("<td class='lib'></td>");
    break;
    }
    var barText = partyType
    
    for (i=0; i < percent; i++)
    {
    document.write(barText);
    So what improvements should I make?
    should my loop be before everything?
    Thanks

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,219
    Thanks
    80
    Thanked 4,453 Times in 4,418 Posts
    You COMPLETELY IGNORED what I told you last week.

    You *STILL* have the "</td>" in the WRONG PLACE!

    WHY do you ASK questions here if you then REFUSE to take the advice and answers we give you???????
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    worldtraveller (11-30-2010)

  • #3
    Regular Coder
    Join Date
    Nov 2010
    Location
    canada
    Posts
    131
    Thanks
    51
    Thanked 0 Times in 0 Posts
    if its all wrong, then what the %$%$# is it supposed to look like? this is so mind boggling

  • #4
    Regular Coder
    Join Date
    Sep 2010
    Location
    Virginia
    Posts
    112
    Thanks
    11
    Thanked 7 Times in 7 Posts
    Quote Originally Posted by worldtraveller View Post
    if its all wrong, then what the %$%$# is it supposed to look like? this is so mind boggling
    Well for one, you are never clear on exactly what it is that you want to accomplish so it's hard for anyone to really help you. We could write out some code snippets for you to give you some examples, but you never give a clear explanation for any of your code.

  • Users who have thanked Afro_Programmer for this post:

    worldtraveller (11-30-2010)

  • #5
    Regular Coder
    Join Date
    Nov 2010
    Location
    canada
    Posts
    131
    Thanks
    51
    Thanked 0 Times in 0 Posts
    Well is complicated I do have a big question from my text that i can show, but its lots to write and no one was willing to help me before

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,219
    Thanks
    80
    Thanked 4,453 Times in 4,418 Posts
    no one was willing to help me before
    NOT TRUE AT ALL!!!

    You got a *LOT* of help. We told you MANY (if not all!) of the things wrong with the code and then you IGNORED what we told you. HOW MANY TIMES did I tell you, for example, that you could not put the </td> into those document.write calls in that switch statement??? At least three times.

    And how many times did we tell you that you keep omitting the + operator when creating concatenated strings?

    And...

    READ RULE 1.5 OF THIS FORUM!

    We are NOT supposed to do your homework for you.

    I finally gave up and did it, because it was apparent that you weren't going to be able to do it yourself. But I'm not going to do it for your next assignment. Programming is a very very exacting science. You can't be sloppy about it. You can't just toss code at the wall and hope it actually runs. You need to learn to do it one step at a time.

    But to say no one was willing to help is just not true. We weren't willing to do the work FOR you. Yes. That's true. But we shouldn't do so.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    worldtraveller (11-30-2010)

  • #7
    Regular Coder
    Join Date
    Nov 2010
    Location
    canada
    Posts
    131
    Thanks
    51
    Thanked 0 Times in 0 Posts
    All right. Thanks for the help I will take my time in posting. Seems things are going in reverse. I will be more precise in my postings. and no more funny comments

  • #8
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,219
    Thanks
    80
    Thanked 4,453 Times in 4,418 Posts
    Have you looked at the answer I gave you in the other thread?

    I guess I should say answers. One answer that does the homework for you, another that shows you at least some of the errors in the latest version you posted.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    worldtraveller (11-30-2010)

  • #9
    Regular Coder
    Join Date
    Nov 2010
    Location
    canada
    Posts
    131
    Thanks
    51
    Thanked 0 Times in 0 Posts
    I did follow your answers, instructions, but when i implemented, nothing at all worked. no offense, i did appreciate your help hands down

  • #10
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,219
    Thanks
    80
    Thanked 4,453 Times in 4,418 Posts
    This is NEARLY unbelievable.

    LOOK HERE:

    http://www.mywhizbang.com/election.htm

    And you say you can't make that code work? I am ABSOLUTELY mystified.
    It works in MSIE.
    It works in FireFox.
    It works in Chrome.
    In what way does it NOT work for you ????
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    worldtraveller (11-30-2010)


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •