Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-29-2010, 12:27 AM   PM User | #1
worldtraveller
Regular Coder

 
Join Date: Nov 2010
Location: canada
Posts: 131
Thanks: 51
Thanked 0 Times in 0 Posts
worldtraveller is an unknown quantity at this point
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
worldtraveller is offline   Reply With Quote
Old 11-29-2010, 09:13 PM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,172
Thanks: 59
Thanked 3,993 Times in 3,962 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
worldtraveller (11-30-2010)
Old 11-29-2010, 09:59 PM   PM User | #3
worldtraveller
Regular Coder

 
Join Date: Nov 2010
Location: canada
Posts: 131
Thanks: 51
Thanked 0 Times in 0 Posts
worldtraveller is an unknown quantity at this point
if its all wrong, then what the %$%$# is it supposed to look like? this is so mind boggling
worldtraveller is offline   Reply With Quote
Old 11-29-2010, 10:30 PM   PM User | #4
Afro_Programmer
Regular Coder

 
Join Date: Sep 2010
Location: Virginia
Posts: 112
Thanks: 11
Thanked 7 Times in 7 Posts
Afro_Programmer is an unknown quantity at this point
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.
Afro_Programmer is offline   Reply With Quote
Users who have thanked Afro_Programmer for this post:
worldtraveller (11-30-2010)
Old 11-29-2010, 10:36 PM   PM User | #5
worldtraveller
Regular Coder

 
Join Date: Nov 2010
Location: canada
Posts: 131
Thanks: 51
Thanked 0 Times in 0 Posts
worldtraveller is an unknown quantity at this point
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
worldtraveller is offline   Reply With Quote
Old 11-29-2010, 11:08 PM   PM User | #6
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,172
Thanks: 59
Thanked 3,993 Times in 3,962 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Quote:
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.
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
worldtraveller (11-30-2010)
Old 11-29-2010, 11:42 PM   PM User | #7
worldtraveller
Regular Coder

 
Join Date: Nov 2010
Location: canada
Posts: 131
Thanks: 51
Thanked 0 Times in 0 Posts
worldtraveller is an unknown quantity at this point
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
worldtraveller is offline   Reply With Quote
Old 11-29-2010, 11:51 PM   PM User | #8
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,172
Thanks: 59
Thanked 3,993 Times in 3,962 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
worldtraveller (11-30-2010)
Old 11-29-2010, 11:59 PM   PM User | #9
worldtraveller
Regular Coder

 
Join Date: Nov 2010
Location: canada
Posts: 131
Thanks: 51
Thanked 0 Times in 0 Posts
worldtraveller is an unknown quantity at this point
I did follow your answers, instructions, but when i implemented, nothing at all worked. no offense, i did appreciate your help hands down
worldtraveller is offline   Reply With Quote
Old 11-30-2010, 12:24 AM   PM User | #10
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,172
Thanks: 59
Thanked 3,993 Times in 3,962 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
worldtraveller (11-30-2010)
Reply

Bookmarks

Tags
break, cells, switch, table

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:56 AM.


Advertisement
Log in to turn off these ads.