JavaScript - I Dont' Get Loops At All, I've Studied For And While And I Don't See How It Applies.
Ok, will do, I guess I could sum up the problem now that I think about it into a very simple question. How do you make a variable variable in a loop? ex
while(i<=20) { _A_+var+ = multiple vars with var endings like the beginning of this one } Please help me figure out how the f to shorten this ... Trying to turn this into a series of loops has been hell on earth (no good at this part of making a website, the javascript part that is) anyways, I was told by someone that was fairly smug that my javascript was retarded, I don't disagree but it works very well and I don't know enough to make it any other way. Please help me figure out how to shorten this rather than complain about the method I used for making the site. If you have a hotfile or rapidshare account I can pay you for your help by uploading 100 files to your account and using those links on my site to earn around $2 - $40 depending on popularity. (That's what I'm estimating though, and it will take about three months since I need to get users first) The site that needs this upgrade http://www.thefreemenu.com Right now this site is at the very beginning stages mostly due to my incompetence but I would really like to start moving things forward. I'm two months into this project and the last week and a half have really stalled to a stop. Its to slow to load and I really need to shorten the javascript so that it doesn't take up 600 k (bananascript version!). The below is repeated 10x for every letter and number as well as a special bit called all1. Here is the first example using _A_1 as the only part that changes. The next set is for the second page of the letter A so its called _A_p2_1, so basically I need this all the way to _A_p10_1 and I need it for all the letters of the alphabet, ex. _B_1, _B_p2_1. I don't understand how to loop but I think that it must be possible, but I really don't get it at all. I've studied loops, while, for and nothing I've learned has helped me solve this problem. Right now my .js file is 3mbs and I need to cut it down. Please help me figure this out, I"m a noob at javascript but I've created some pretty complex things and somehow manage to have them work. I think I'll get it if you can provide a small example using what I need to work with. Code: _A_0[0]='<ul class="freemenu"><li class="movieimage'; _A_0[1]='"><img src="images\/movies\/'; _A_0[2]='.png" width="75" height="120" \/><ul>\n <li class="hotlink'; _A_0[3]='"><a href="#" onmouseout="this.style.opacity=0.4;this.filters.alpha.opacity=40" onmouseover="this.style.opacity=1;this.filters.alpha.opacity=100" onclick="addText(\''; _A_0[4]='\')"><img src="images\/hotfile.png" width="70" height="43" \/><\/a><\/li>\n <li class="rapidlink'; _A_0[5]='\')"><img src="images\/rapidshare.png" width="55" height="50"\/><\/a><\/li>\n <li class="information'; _A_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]+_nl_0[20]+_A_0[6]+_i_0[20]+_A_0[7]); var _20_0=(_AC_0[1]+_AC_0[2]+_AC_0[3]+_AC_0[4]+_AC_0[5]+_AC_0[6]+_AC_0[7]+_AC_0[8]+_AC_0[9]+_AC_0[10]+_AC_0[11]+_AC_0[12]+_AC_0[13]+_AC_0[14]+_AC_0[15]+_AC_0[16]+_AC_0[17]+_AC_0[18]+_AC_0[19]+_AC_0[20]); _A_p2_0[0]='<ul class="freemenu"><li class="movieimage'; _A_p2_0[1]='"><img src="images\/movies\/'; _A_p2_0[2]='.png" width="75" height="120" \/><ul>\n <li class="hotlink'; _A_p2_0[3]='"><a href="#" onmouseout="this.style.opacity=0.4;this.filters.alpha.opacity=40" onmouseover="this.style.opacity=1;this.filters.alpha.opacity=100" onclick="addText(\''; _A_p2_0[4]='\')"><img src="images\/hotfile.png" width="70" height="43" \/><\/a><\/li>\n <li class="rapidlink'; _A_p2_0[5]='\')"><img src="images\/rapidshare.png" width="55" height="50"\/><\/a><\/li>\n <li class="information'; _A_p2_0[6]='">\n <textarea name="textarea" cols="51" rows="30" style="overflow:hidden;" readonly="readonly" wrap="virtual" >'; _A_p2_0[7]='<\/textarea>\n <\/li>\n<\/ul>\n<\/li>\n <\/ul>\n'; _AC_p2_0[1]=(_A_p2_0[0]+_nl_p2_0[1]+_A_p2_0[1]+_img_p2_0[1]+_A_p2_0[2]+_nl_p2_0[1]+_A_p2_0[3]+_h_p2_0[1]+_A_p2_0[4]+_nl_p2_0[1]+_A_p2_0[3]+_r_p2_0[1]+_A_p2_0[5]+_nl_p2_0[1]+_A_p2_0[6]+_i_p2_0[1]+_A_p2_0[7]); _AC_p2_0[2]=(_A_p2_0[0]+_nl_p2_0[2]+_A_p2_0[1]+_img_p2_0[2]+_A_p2_0[2]+_nl_p2_0[2]+_A_p2_0[3]+_h_p2_0[2]+_A_p2_0[4]+_nl_p2_0[2]+_A_p2_0[3]+_r_p2_0[2]+_A_p2_0[5]+_nl_p2_0[2]+_A_p2_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[17]+_A_p2_0[7]); _AC_p2_0[18]=(_A_p2_0[0]+_nl_p2_0[18]+_A_p2_0[1]+_img_p2_0[18]+_A_p2_0[2]+_nl_p2_0[18]+_A_p2_0[3]+_h_p2_0[18]+_A_p2_0[4]+_nl_p2_0[18]+_A_p2_0[3]+_r_p2_0[18]+_A_p2_0[5]+_nl_p2_0[18]+_A_p2_0[6]+_i_p2_0[18]+_A_p2_0[7]); _AC_p2_0[19]=(_A_p2_0[0]+_nl_p2_0[19]+_A_p2_0[1]+_img_p2_0[19]+_A_p2_0[2]+_nl_p2_0[19]+_A_p2_0[3]+_h_p2_0[19]+_A_p2_0[4]+_nl_p2_0[19]+_A_p2_0[3]+_r_p2_0[19]+_A_p2_0[5]+_nl_p2_0[19]+_A_p2_0[6]+_i_p2_0[19]+_A_p2_0[7]); _AC_p2_0[20]=(_A_p2_0[0]+_nl_p2_0[20]+_A_p2_0[1]+_img_p2_0[20]+_A_p2_0[2]+_nl_p2_0[20]+_A_p2_0[3]+_h_p2_0[20]+_A_p2_0[4]+_nl_p2_0[20]+_A_p2_0[3]+_r_p2_0[20]+_A_p2_0[5]+_nl_p2_0[20]+_A_p2_0[6]+_i_p2_0[20]+_A_p2_0[7]); var _20_p2_0=(_AC_p2_0[1]+_AC_p2_0[2]+_AC_p2_0[3]+_AC_p2_0[4]+_AC_p2_0[5]+_AC_p2_0[6]+_AC_p2_0[7]+_AC_p2_0[8]+_AC_p2_0[9]+_AC_p2_0[10]+_AC_p2_0[11]+_AC_p2_0[12]+_AC_p2_0[13]+_AC_p2_0[14]+_AC_p2_0[15]+_AC_p2_0[16]+_AC_p2_0[17]+_AC_p2_0[18]+_AC_p2_0[19]+_AC_p2_0[20]); Another part that I'm not so worried about but that still takes up a ton of space is the corresponding variables that need to be set as blank, this one being for a instead of 0(zero) like in the previous example. Code: var _nl_a =new Array() var _img_a =new Array() var _h_a =new Array() var _r_a =new Array() var _i_a =new Array() var _A_a =new Array() var _AC_a =new Array() _nl_a[1] = 1; _img_a[1] = 'nocontent7'; _h_a[1] = ''; _r_a[1] = ''; _i_a[1] = ''; _nl_a[2] = 2; _img_a[2] = 'nocontent7'; _h_a[2] = ''; _r_a[2] = ''; _i_a[2] = ''; _nl_a[3] = 3; _img_a[3] = 'nocontent7'; _h_a[3] = ''; _r_a[3] = ''; _i_a[3] = ''; _nl_a[4] = 4; _img_a[4] = 'nocontent7'; _h_a[4] = ''; _r_a[4] = ''; _i_a[4] = ''; _nl_a[5] = 5; _img_a[5] = 'nocontent7'; _h_a[5] = ''; _r_a[5] = ''; _i_a[5] = ''; _nl_a[6] = 6; _img_a[6] = 'nocontent5'; _h_a[6] = ''; _r_a[6] = ''; _i_a[6] = ''; _nl_a[7] = 7; _img_a[7] = 'nocontent5'; _h_a[7] = ''; _r_a[7] = ''; _i_a[7] = ''; _nl_a[8] = 8; _img_a[8] = 'nocontent5'; _h_a[8] = ''; _r_a[8] = ''; _i_a[8] = ''; _nl_a[9] = 9; _img_a[9] = 'nocontent5'; _h_a[9] = ''; _r_a[9] = ''; _i_a[9] = ''; _nl_a[10] = 10; _img_a[10] = 'nocontent5'; _h_a[10] = ''; _r_a[10] = ''; _i_a[10] = ''; _nl_a[11] = 11; _img_a[11] = 'nocontent8'; _h_a[11] = ''; _r_a[11] = ''; _i_a[11] = ''; _nl_a[12] = 12; _img_a[12] = 'nocontent8'; _h_a[12] = ''; _r_a[12] = ''; _i_a[12] = ''; _nl_a[13] = 13; _img_a[13] = 'nocontent8'; _h_a[13] = ''; _r_a[13] = ''; _i_a[13] = ''; _nl_a[14] = 14; _img_a[14] = 'nocontent8'; _h_a[14] = ''; _r_a[14] = ''; _i_a[14] = ''; _nl_a[15] = 15; _img_a[15] = 'nocontent8'; _h_a[15] = ''; _r_a[15] = ''; _i_a[15] = ''; _nl_a[16] = 16; _img_a[16] = 'nocontent6'; _h_a[16] = ''; _r_a[16] = ''; _i_a[16] = ''; _nl_a[17] = 17; _img_a[17] = 'nocontent6'; _h_a[17] = ''; _r_a[17] = ''; _i_a[17] = ''; _nl_a[18] = 18; _img_a[18] = 'nocontent6'; _h_a[18] = ''; _r_a[18] = ''; _i_a[18] = ''; _nl_a[19] = 19; _img_a[19] = 'nocontent6'; _h_a[19] = ''; _r_a[19] = ''; _i_a[19] = ''; _nl_a[20] = 20; _img_a[20] = 'nocontent6'; _h_a[20] = ''; _r_a[20] = ''; _i_a[20] = ''; var _nl_p2_a =new Array() var _img_p2_a =new Array() var _h_p2_a =new Array() var _r_p2_a =new Array() var _i_p2_a =new Array() var _A_p2_a =new Array() var _AC_p2_a =new Array() _nl_p2_a[1] = 1; _img_p2_a[1] = 'nocontent9'; _h_p2_a[1] = ''; _r_p2_a[1] = ''; _i_p2_a[1] = ''; _nl_p2_a[2] = 2; _img_p2_a[2] = 'nocontent9'; _h_p2_a[2] = ''; _r_p2_a[2] = ''; _i_p2_a[2] = ''; _nl_p2_a[3] = 3; _img_p2_a[3] = 'nocontent9'; _h_p2_a[3] = ''; _r_p2_a[3] = ''; _i_p2_a[3] = ''; _nl_p2_a[4] = 4; _img_p2_a[4] = 'nocontent9'; _h_p2_a[4] = ''; _r_p2_a[4] = ''; _i_p2_a[4] = ''; _nl_p2_a[5] = 5; _img_p2_a[5] = 'nocontent9'; _h_p2_a[5] = ''; _r_p2_a[5] = ''; _i_p2_a[5] = ''; _nl_p2_a[6] = 6; _img_p2_a[6] = 'nocontent7'; _h_p2_a[6] = ''; _r_p2_a[6] = ''; _i_p2_a[6] = ''; _nl_p2_a[7] = 7; _img_p2_a[7] = 'nocontent7'; _h_p2_a[7] = ''; _r_p2_a[7] = ''; _i_p2_a[7] = ''; _nl_p2_a[8] = 8; _img_p2_a[8] = 'nocontent7'; _h_p2_a[8] = ''; _r_p2_a[8] = ''; _i_p2_a[8] = ''; _nl_p2_a[9] = 9; _img_p2_a[9] = 'nocontent7'; _h_p2_a[9] = ''; _r_p2_a[9] = ''; _i_p2_a[9] = ''; _nl_p2_a[10] = 10; _img_p2_a[10] = 'nocontent7'; _h_p2_a[10] = ''; _r_p2_a[10] = ''; _i_p2_a[10] = ''; _nl_p2_a[11] = 11; _img_p2_a[11] = 'nocontent10'; _h_p2_a[11] = ''; _r_p2_a[11] = ''; _i_p2_a[11] = ''; _nl_p2_a[12] = 12; _img_p2_a[12] = 'nocontent10'; _h_p2_a[12] = ''; _r_p2_a[12] = ''; _i_p2_a[12] = ''; _nl_p2_a[13] = 13; _img_p2_a[13] = 'nocontent10'; _h_p2_a[13] = ''; _r_p2_a[13] = ''; _i_p2_a[13] = ''; _nl_p2_a[14] = 14; _img_p2_a[14] = 'nocontent10'; _h_p2_a[14] = ''; _r_p2_a[14] = ''; _i_p2_a[14] = ''; _nl_p2_a[15] = 15; _img_p2_a[15] = 'nocontent10'; _h_p2_a[15] = ''; _r_p2_a[15] = ''; _i_p2_a[15] = ''; _nl_p2_a[16] = 16; _img_p2_a[16] = 'nocontent2'; _h_p2_a[16] = ''; _r_p2_a[16] = ''; _i_p2_a[16] = ''; _nl_p2_a[17] = 17; _img_p2_a[17] = 'nocontent2'; _h_p2_a[17] = ''; _r_p2_a[17] = ''; _i_p2_a[17] = ''; _nl_p2_a[18] = 18; _img_p2_a[18] = 'nocontent2'; _h_p2_a[18] = ''; _r_p2_a[18] = ''; _i_p2_a[18] = ''; _nl_p2_a[19] = 19; _img_p2_a[19] = 'nocontent2'; _h_p2_a[19] = ''; _r_p2_a[19] = ''; _i_p2_a[19] = ''; _nl_p2_a[20] = 20; _img_p2_a[20] = 'nocontent2'; _h_p2_a[20] = ''; _r_p2_a[20] = ''; _i_p2_a[20] = ''; PLEASE PLEASE HELP ME FIGURE OUT HOW I CAN CUT THIS DOWN! It's been driving me insane for awhile now and I can't go any further until this is taken care of. Similar TutorialsHey, I am needing some help trying to remember what is the name of this type of javascript content expand script. It looks like this: It doesnt have to look like that but the same general example of expanding and contracting tabs with the arrow that switches when its open and closed. Thanks alot! Some links would be nice. Please Check the webpage to see what I am trying to do. I am told It cant be done in HTML. That I will have to use Java Script. Can someone Please help me out here. Go to: http://www.capthelm.net If You can assist me please use the email link on my site. Thanks. The Captain I have buttons that check all the check boxes and uncheck all the checkboxes. They seem to not be working. Here is the code. Javascript Code: <script type="text/javascript"> function checkall(delchk) { for (i = 0; i < delchk.length; i++) delchk[i].checked = true; } </script> <script type="text/javascript"> function uncheckall(delchk) { for (i = 0; i < delchk.length; i++) delchk[i].checked = false; } </script> PHP PHP Code: <?php error_reporting(E_ALL); require("inc/config.php"); if (isset($_POST['del'])) { for ($count = 0;$count<count($_POST[delchk]);$count++) { $delete = $_POST[delchk][$count]; $query = "DELETE FROM persons WHERE id = '$delete'"; $result = mysql_query($query); if (!$result) { die("Error deleting persons! Query: $query<br />Error: ".mysql_error()); } } } $result = mysql_query("SELECT * FROM persons"); // Check how many rows it found if(mysql_num_rows($result) > 0){ echo "<table id=\"mytable\"> <thead> <tr> <th align=\"center\" scope=\"col\">Delete?</th> <th align=\"center\" scope=\"col\">First Name</th> <th align=\"center\" scope=\"col\">Last Name</th> <th align=\"center\" scope=\"col\">Profile</th> <th align=\"center\" scope=\"col\">Date</th> <th align=\"center\" scope=\"col\">IP Address</th> </tr> </thead> <tbody>"; echo "<form name = 'myform' action='' method='post'>"; while($row = mysql_fetch_array($result)) { echo "<tr align=\"center\">"; echo '<td><input type="checkbox" id="delchk" name="delchk[]" value="'.$row['id'].'" /></td>'; echo "<td>" . $row['FirstName'] . "</td>"; echo "<td>" . $row['LastName'] . "</td>"; echo "<td><a target=frame2 href='" ."profile.php?user1=". $row['FirstName'] ."'>Check Profile</a></td>"; echo "<td>" . $row['AddedDate'] . "</td>"; echo "<td>" . $row['Ip'] . "</td>"; echo "</tr>"; } echo "</tbody>"; echo "</table>"; echo "<hr>"; echo "<input type='submit' name = 'del' value='Delete Selected'></form>"; echo "<input type='button' onclick='checkall(document.myform[\"delchk[]\"]);' value='Select All'>"; echo "<input type='button' onclick='uncheckall(document.myform[\"delchk[]\"]);' value='UnSelect All'>"; } else{ // No rows were found ... echo 'No registered members.'; } mysql_close(); ?> Hi, it's my first post and first thread, actually I joined to ask this question. I did try searching first but for some reason when I put this character in google search fields I never find what I want, maybe not being recognized. here's the code Code: this.size=a.size||2000; this.handle_event=a.handle_event||'click'; my question ... what is the || character(s)? I'm sure this must be laughably simple and thanks in advance (new to learning js) I have a site that works just fine in fire fox but surprise surprise, there is a lot of problems in IE8 that dont make sense at all. Here is my link: http://paperlesswasp.com/royalvillicus/recompare.php Code: <span class="menu1" id="menu1"> <map name="menu1" id="menu1"> <area alt="memberships" shape="rect" coords="134, 143, 176, 166" href="http://realtor.com"/> <area alt="memberships" shape="rect" coords="188, 143, 231, 166" href="http://realestate.yahoo.com/"/> <area alt="memberships" shape="rect" coords="243, 143, 285, 166" href="http://realestate.com"/> <area alt="memberships" shape="rect" coords="297, 143, 340, 166" href="http://frontdoor.com"/> <area alt="memberships" shape="rect" coords="351, 143, 394, 166" href="http://homes.com"/> </map> <img src="image/rsummary.png" alt="site comparison" usemap="#menu1" width="" height="" vspace="5" hspace="1"/><br><br> </span> <span id="ex_10" style="display:none;"> <img src="image/rranking.png" name="ex_4" id="ex_4" alt="ranking" width="" height="" vspace="5" hspace="1"/><br> </span> <span id="ex_9" style="display:none;"> <img src="image/relistings.png" name="ex_5" id="ex_5" alt="listings" width="" height="" vspace="5" hspace="1"/><br> </span> <span id="ex_6" style="display:none;"> <img src="image/relistingsearches.png" name="ex_6" id="ex_6" alt="listings searches" width="" height="" vspace="5" hspace="1"/><br> </span> <span id="ex_7" style="display:none;"> <img src="image/recalculators.png" name="ex_7" id="ex_7" alt="calculators" width="" height="" vspace="5" hspace="1"/><br> </span> <span id="ex_8" style="display:none;"> <img src="image/reresources.png" name="ex_8" id="ex_8" alt="resources" width="" height="" vspace="5" hspace="1"/><br> </span> <span id="ex_11" style="display:none;"> <img src="image/remarketdata.png" name="ex_8" id="ex_8" alt="resources" width="" height="" vspace="5" hspace="1"/><br> </span> if you look under: http://paperlesswasp.com/royalvillicus/calculator.php IE8 will only show 2 out of the 7 drop down menu bars that are suppose to be there. works in IE8 and firefox Code: <img src="image/wroi.png" onmouseover="rollOn(this)" onmouseout="rollOff(this)" onclick="showMe(12)" vspace="1" hspace="1" class="position"><br><br> works only in firefox Code: <img src="image/wtax.png" onmouseover="rollOn(this)" onmouseout="rollOff(this)" onclick="showMe(11)" vspace="1" hspace="1" class="position"><br><br> Fire fox handles these just fine, but IE8 doesnt. I appreciate any siggestions Hey Guys! I've previously done HTML, but now started to learn some aspects of Javascript but getting rather confused with Loops! I've done a some coding for the Loop question (probably doesn't make sense) but I was wondering if you could help me out? I'm about as confused as a cow on a Astro Turf so my code may look terrible! - For this question you will: Draw a flow chart and write a javascript function which will use a for loop and allow the user to enter the details for four students when the program is run and display the average. Assume that they equal weighting. Hint: Javascript may assume that the value received from a prompt is a string so use parseInt() to make sure the number is an integer. Here is my code: (I'm using Aptana) Code: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <meta http-equiv="Content-Type" content="text/javascript; charset=utf-8"/> <title>Average Marks</title> <!-- Date: 2011-10-27 --> <head> <script type="text/javascript"> function marks () { var mark1 = 10; var mark2 = 25; var mark3 = 50; for(var mark1 = 10; mark1<20; mark1++) (var mark2 = 25; mark2<50; mark2++) (var mark3 = 50; mark3<90; mark3++) { alert(mark1 + "<br /> "); (mark2 + "<br /> "); (mark3 + "<br />" ); console.log(mark1) console.log(mark2) console.log(mark3) } } function average () { parseInt() } </script> <body onload="marks()"> </body> </head> </html> P.S. I'm not using the prompt for the user to enter their details yet, as I wanted to test it with the marks already set. Regards Hello, i am new here however my knowledge is not that limited like that one guy wolf who oldMaster was helping with i read the RULES and his thread lol so my question is, i have made a for loop and in side the for loop i wrote document.write(<td>date</td>"<td class = 'amt'>amount</td>); where date, amount, firstName, and lastName, are the values of the date, amount, firstName, and lastName arrays for the index indicated by the current value of the for loop counter varible so questions : i have spent the past 3 days looking online for the correct answer document.write(<td>date</td>"<td class = 'amt'>amount</td>); ? HTML FILE Code: <title>The Lighthouse</title> <link href="lhouse.css" rel="stylesheet" type="text/css" /> <script type = "text/javascript" src = "list.js"></script> <!-- caling the external file --> <script type ="text/javascript"> function amountTotal(){ //i dont think we need an array made because we have called the external file called list.js which holds the arrays //sets the variable to 0 var total = 0; //new Array("firstName", "lastName", "street", "city", "state", "zip", "amount", "date"); //that loops through all the values in the amount array, at each point in the loop add the current value of the array item to the value of the total variable for(var i = 0; i < amount.length; i++) { total = total + amount[i]; }//enf forloop //i must return the sum of all the values in the amount array return total; }//end of function total </script> </head> <body> <div id="title"> <img src="logo.jpg" alt="The Lighthouse" /> The Lighthouse<br /> 543 Oak Street<br /> Owensboro, KY 42302<br/> (270) 555-7511 </div> <div id="data_list"> <!--//creates a new script --> <script type = "text/javascript"> document.write("<table border='1' rules='rows' cellspacing='0'>"); document.write("<tr>"); document.write("<th>Date</th><th>Amount</th><th>First Name</th>"); document.write("<th>Last Name</th><th>Address</th>"); document.write("</tr>"); document.write("</table>"); for(var i = 0; i < date.length; i++) { if(i % 2 ) document.write("<tr>"); else document.write("<tr class='yellowrow'>"); document.write("<td>"date"</td>"<td class = 'amt'>amount"</td>"); }//end for </script> </div> <div id="totals"> <!--//this creates a script --> <script type = "text/javascript"> //this is how to print a table to the screen only when html is inside a script document.write( <table border='1' cellspacing='1'> <tr> <th id ='sumTitle' colspan='2'> Summary </th> </tr> <tr> <th>Contributors</th> <th>contributions</th> </tr> <tr> <th>Amount</th> <td>$total</td> </tr> </table>); </script> </div> </body> </html> THIS IS THE ARRAY LIST WHICH IS THE EXTERNAL FILE Code: firstName = new Array(); lastName = new Array(); street = new Array(); city = new Array(); state= new Array(); zip = new Array(); amount = new Array(); date = new Array() firstName[0]="Nina"; lastName[0]="Largent"; street[0]="88 Regal Lane"; city[0]="Williamsburg"; state[0]="KY"; zip[0]="40769"; amount[0]=125; date[0]="2011-09-18"; firstName[1]="Mike"; lastName[1]="Hunt"; street[1]="Da404 Barrow Street"; city[1]="London"; state[1]="KY"; zip[1]="40742"; amount[1]=75; date[1]="2011-09-18"; firstName[2]="Monica"; lastName[2]="Lang"; street[2]="743 Stawlings Drive"; city[2]="Danville"; state[2]="KY"; zip[2]="40423"; amount[2]=50; date[2]="2011-09-16"; firstName[3]="William"; lastName[3]="Mcknight"; street[3]="102 Maple Lane"; city[3]="Danville"; state[3]="KY"; zip[3]="40423"; amount[3]=150; date[3]="2011-09-15"; firstName[4]="Latrina"; lastName[4]="Hults"; street[4]="750 Whitehall Road"; city[4]="London"; state[4]="KY"; zip[4]="40742"; amount[4]=250; date[4]="2011-09-14"; firstName[5]="Danny"; lastName[5]="Shamblin"; street[5]="123 Smith Drive"; city[5]="Owensboro"; state[5]="KY"; zip[5]="42303"; amount[5]=50; date[5]="2011-09-13"; firstName[6]="Tina"; lastName[6]="Ammons"; street[6]="888 Evans Way"; city[6]="Williamsburg"; state[6]="KY"; zip[6]="40769"; amount[6]=50; date[6]="2011-09-13"; firstName[7]="Joanne"; lastName[7]="Fine"; street[7]="210 Bowling Terrace"; city[7]="Williamsburg"; state[7]="KY"; zip[7]="40769"; amount[7]=125; date[7]="2011-09-11"; firstName[8]="Charlotte"; lastName[8]="Foulk"; street[8]="109 South Road"; city[8]="Danville"; state[8]="KY"; zip[8]="40423"; amount[8]=50; date[8]="2011-09-10"; firstName[9]="Candice"; lastName[9]="Alfaro"; street[9]="108 Atwood Avenue"; city[9]="Owensboro"; state[9]="KY"; zip[9]="42303"; amount[9]=400; date[9]="2011-09-08"; firstName[10]="Kristi"; lastName[10]="Laine"; street[10]="512 North Lane"; city[10]="Williamsburg"; state[10]="KY"; zip[10]="40769"; amount[10]=225; date[10]="2011-09-08"; firstName[11]="Elisabeth"; lastName[11]="Carbone"; street[11]="381 Main Street"; city[11]="London"; state[11]="KY"; zip[11]="40742"; amount[11]=200; date[11]="2011-09-07"; firstName[12]="James"; lastName[12]="Larsen"; street[12]="212 Rawlings Way"; city[12]="Jackson"; state[12]="KY"; zip[12]="41339"; amount[12]=125; date[12]="2011-09-07"; firstName[13]="Ralph"; lastName[13]="Thornton"; street[13]="444 Smith Drive"; city[13]="Owensboro"; state[13]="KY"; zip[13]="42303"; amount[13]=100; date[13]="2011-09-07"; firstName[14]="Robin"; lastName[14]="Witt"; street[14]="78 Norland Pines"; city[14]="London"; state[14]="KY"; zip[14]="40742"; amount[14]=75; date[14]="2011-09-07"; firstName[15]="Alex"; lastName[15]="Ruiz"; street[15]="102 Sunset Road"; city[15]="Jackson"; state[15]="KY"; zip[15]="41339"; amount[15]=50; date[15]="2011-09-06"; firstName[16]="Callie"; lastName[16]="Rudy"; street[16]="3 Sunset Road"; city[16]="Jackson"; state[16]="KY"; zip[16]="41339"; amount[16]=50; date[16]="2011-09-06"; firstName[17]="Michael"; lastName[17]="Harrell"; street[17]="125 Sunset Road"; city[17]="Jackson"; state[17]="KY"; zip[17]="41339"; amount[17]=50; date[17]="2011-09-06"; firstName[18]="Edgar"; lastName[18]="Morales"; street[18]="387 North Lane"; city[18]="Williamsburg"; state[18]="KY"; zip[18]="40769"; amount[18]=250; date[18]="2011-09-05"; firstName[19]="Arlene"; lastName[19]="Lutz"; street[19]="7888 Clear View Drive"; city[19]="Danville"; state[19]="KY"; zip[19]="40423"; amount[19]=75; date[19]="2011-09-05"; firstName[20]="Earl"; lastName[20]="Holmes"; street[20]="1001 Rawlings Way"; city[20]="Jackson"; state[20]="KY"; zip[20]="41339"; amount[20]=500; date[20]="2011-09-04"; firstName[21]="Bernice"; lastName[21]="Drew"; street[21]="25 Main Street"; city[21]="London"; state[21]="KY"; zip[21]="40742"; amount[21]=150; date[21]="2011-09-04"; firstName[22]="Patrick"; lastName[22]="Granier"; street[22]="100 Atwood Avenue"; city[22]="Owensboro"; state[22]="KY"; zip[22]="42303"; amount[22]=75; date[22]="2011-09-03"; firstName[23]="Henry"; lastName[23]="Bailey"; street[23]="37 East Maple Street"; city[23]="Danville"; state[23]="KY"; zip[23]="40423"; amount[23]=50; date[23]="2011-09-03"; firstName[24]="Ginny"; lastName[24]="Rainey"; street[24]="657 Dawson Lane"; city[24]="Danville"; state[24]="KY"; zip[24]="40423"; amount[24]=50; date[24]="2011-09-03"; firstName[25]="Ginny"; lastName[25]="Rainey"; street[25]="657 Dawson Lane"; city[25]="Danville"; state[25]="KY"; zip[25]="40423"; amount[25]=75; date[25]="2011-09-03"; firstName[26]="Basilia"; lastName[26]="Lu"; street[26]="851 Flad Court"; city[26]="Jackson"; state[26]="KY"; zip[26]="41339"; amount[26]=500; date[26]="2011-09-02"; firstName[27]="Livia"; lastName[27]="Mckinnon"; street[27]="557 Ivy Avenue"; city[27]="Jackson"; state[27]="KY"; zip[27]="41339"; amount[27]=50; date[27]="2011-08-31"; firstName[28]="Kris"; lastName[28]="Levesque"; street[28]="542 Upton Avenue"; city[28]="Owensboro"; state[28]="KY"; zip[28]="42303"; amount[28]=100; date[28]="2011-08-31"; firstName[29]="Lynwood"; lastName[29]="Ingersoll"; street[29]="723 Jackson Avenue"; city[29]="Owensboro"; state[29]="KY"; zip[29]="42303"; amount[29]=500; date[29]="2011-08-30"; firstName[30]="Petronila"; lastName[30]="Damico"; street[30]="44 Stewart Street"; city[30]="London"; state[30]="KY"; zip[30]="40742"; amount[30]=250; date[30]="2011-08-30"; firstName[31]="Hugh"; lastName[31]="Warren"; street[31]="585 Lindon Court"; city[31]="Williamsburg"; state[31]="KY"; zip[31]="40769"; amount[31]=50; date[31]="2011-08-28"; firstName[32]="Tom"; lastName[32]="Thomas"; street[32]="Rigel Avenue"; city[32]="London"; state[32]="KY"; zip[32]="40742"; amount[32]=100; date[32]="2011-08-27"; firstName[33]="Steve"; lastName[33]="Bones"; street[33]="900 Lawton Street"; city[33]="Williamsburg"; state[33]="KY"; zip[33]="40769"; amount[33]=50; date[33]="2011-08-25"; firstName[34]="Jeri"; lastName[34]="White"; street[34]="Hawkes Lane"; city[34]="Owensboro"; state[34]="KY"; zip[34]="42303"; amount[34]=150; date[34]="2011-08-25"; Hello codingforums.com! Right, this is probably going but such a stupid newbie thread but here goes.. I've finally got myself into gear to start learning javascript. I've been watching video tutorials, learning from websites and simply learning by error. I understand the concept of for loops, but the whole nested thing doesn't seem to click for some reason. I thought i understood and managed to write a piece of code that constantly writes '*' across the screen. Could someone with some pretty damn good knowledge of javascript be able to walk me through step by step of my script to explain what actually is happening? It would help loads. here is the script, many thanks!! <script type="text/javascript"> var counter = 0; function writeStars(){ for(i=0;i<1;i++){ for(a=0;a<=counter;a++){ document.write("*"); } counter++ document.write("<br />"); } } setInterval("writeStars()", 200); </script> I've been asked to create a program which allows meteorologists to input a certain amount of data inputs of snowfall, and then the individual snowfall of each input itself. In my mind this should prompt me for a data input as many times as their are inputs, however, it works only for the first data input, then it returns to blank page without prompts for the second input... Any clues as to where I'm going wrong? Hello all. I've spent a few days now browsing this forum along with guides on the net, I'm new to JS and I'm having a bit of trouble with loops. I just don't seem to get them, I was wondering if anyone had any tips or methods (the simpler the better ) for getting these learnt and done with? Would appreciate any tips Thanks Hi everyone. I have a loop question. This is my assignment for my Comp Apps class. The whole thing is a store selling guitar picks. What I'm missing now is a loop. After the costumer places the order, he has the choice to go back and buy more or complete the order. In the end all the order the costumer placed adds up to the total. This is what I have so far: PHP Code: <script type="text/javascript"> var name = prompt("Welcome to Pick Center. Please enter your name", " "); alert("Hello " + name + "! Please look through our list of picks before placing your order."); var product = prompt("What would you like to buy?", ""); var quantity = prompt("How many " + product + " would you like to order?", ""); var confirming = confirm(""+ name + " you ordered " + quantity +" " + product +" picks. Is this correct?"); var price = " "; var item_discount = " "; if ( confirming == true ) { } else { alert("Refresh the page to reload and place a new order.")} if ( product == "dirtbag" ) { price = "5"; item_discount = "0.3";} else if ( product == "delrin" ) { price = "7"; item_discount = "0.2";} else if ( product == "speedpick" ) { price = "10"; item_discount = "0.5";} else if ( product == "stubby") { price = "25"; item_discount = "0.25";} else { alert("Sorry," + name + ". You entered an invalid product. Refresh the page to reload and place the order again.");} var cost_of_order = price * quantity; var discount = price * item_discount * quantity; var total = cost_of_order - discount; document.write("<br><h1> Your Order: </h1></br><br>"); document.write("Thank you for placing an order with us, <b>" + name + "</b>.<br><br>"); document.write("The cost of buying " + quantity + " " + product + " picks is <b>$" + cost_of_order + "</b>.<br><br>"); document.write("The discount for this purchase is <b>$" + discount + "</b>.<br><br>"); document.write("With discount, your total order cost is <b>$" + total + "</b>.<br><br>"); </script> I've tried reading around and I bought a couple of books but I just can't get a grasp on loops. Can someone please help me with this? I have the following nested for loops: Code: for (i;i<tag('entry').length;i++) { content = content + '<tr>'; for (x;x<tag('header').length;x++) { content = content + '<td style="width:' + tdWidth + '%; border:solid 1px #000;">' + tag('item')[x].firstChild.nodeValue; + '</td>'; } x+=tag('header').length; content = content + '</tr>'; } For some reason, it seems to only loop the outer for loop once. BTW, tag() is defined, I just didn't include it. Help is appreciated. Thanks, Julian I am working on making 2 for loops of 2 arrays to get the total of them. Then I need to get the average heights. This is for a test, yet I have not got a clue, so I need clues as I cant get it to work and I am a new coder to javascript. Code: var heights = [15,16,17,18,19]; var numbers = [2,1,6,4,2]; var average = new Array(5); average = 0 for (var heights = 0; heights <= 5; heights = heights+ 1) { total = 0 } for (var numbers = 0; numbers <= 5; numbers = numbers + 1) { total = 0 average = heights / numbers; } document.write('The average height is ' + average); Am I on the right road? I need to use this format and not functions. I have got 2 for statements but maybe I could do this with one, it is so tricky this javascript. I am doing practice problems for class (not homework), and I've gotten most of the coding down except for one stipulation. The exercise reads: "Write a program that reads input of the number of hours an employee has worked and displays the employee's total and average (per day) number of hours. The company doesn't pay overtime, so cap any day at 8 hours. Sample Run: How many days? 3 Hours? 6 Hours? 12 Hours? 5 Employee's total paid hours = 19 Employee’s average paid hours = 6.3333333" I can't figure out how to include the bolded stipulation. I've tried adding: Code: if ( sum >8 ) { sum = 8; } but I know that isn't right, and I can't think of any other solution. Can someone advise me on my work? Code: public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); System.out.println("How many days worked? "); int count = keyboard.nextInt(); int i = 1; int sum = 0; while (i <= count) { System.out.println("Hours? "); sum += keyboard.nextInt(); i++; } System.out.println("Employee's total paid hours= " +sum); System.out.println("Employee's average paid hours= " +(double)sum/count); } } Also! If anyone can explain to me why there has to be an initialization of " int sum = 0 ", that would be great. I just know I have to include it for this loop. I created a For Loop and counter starts at 0, then increase in increments of 1 after each iteration of loop i run a command 1( add html code such as Code: <td>named (part)</td> <td class= 'num'>votes</td> Then create variable of named percent use totalV for value of sum parameter then i add html code of Code: <td class='num'>(percent%(</td> then i add a function named createBar(0 using race[0], name1, party1, and votes1 in parameter values this is my coding Code: for (var i=0; i < name.length; i++) { document.write("<tr>"); document.write("<td>" name[i] + "(" + party[i] + ")</td>"); document.write("<td class='num'>" + votes[i] + "</td>"); var percent=calcPercent(votes[i], totalV) document.write("<td class='num'>(" + percent +"%)</td>"); createBar(party[i],percent) document.write("</tr>"); } document.write("</table>"); } </script> </head> so any improvements or what i am missing in my functions. This is a final loops in an exercise here is my code Code: <script type="text/javascript"> var counter; for (counter=0; counter<amount.length; counter++) {} { document.writeIn(counter+"<br/>"); document.writeIn("<tr><td>"date"[counter]"</td>"); document.writeIn("<td class = 'amt'>myArray</td>"); document.writeIn("<td>"firstName[counter]"</td>"); document.writeIn("<td>"lastName[counter]"</td>"); document.writeIn("<td>"street[counter]"<br />"); document.writeIn("<td>"+street[counter]+" "+city[counter]+" "state[counter]+" "+zip[counter]+"</td></tr>); Total=total+amount[counter]; document.writeIn("<table>"); } </script> This is what i have, what do i need to do to make this more proper and written properly? thanks Hey Guys, I'm currently a seasoned programmer who is in a programming class at my school. We're currently learning advanced JavaScript, and we're on the topic of nested loops. After teaching us about for and while loops, my teacher gave us a little puzzle to solve. It's kind of difficult to explain, but I'll give you guys my current code and what it outputs. Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Word Reversal</title> <script type="text/javascript"> var ask = prompt("How many words do you want?",""); while (ask < "1") { alert("You have to have at least one word!"); var ask = prompt("How many words do you want?",""); } var num = parseInt(ask) + 1; var final = ""; for (var i=1; i < num; i++) { var word = prompt("What's word " + i + "?"); final = final + "Word " + i +": " + word + "<br/>"; } </script> </head> <body> <script type="text/javascript"> document.writeln(final); </script> </body> </html> The current output, when the user wants two words, and word 1 is one and word 2 is two, comes out to be: Code: Word 1: one Word 2: two Which is great, but the only problem is, this is what the output's supposed to be: Code: Word 2: two Word 1: one I'm stumped. I've had numerous programming challenges in my life which I've solved, but I'm not sure where to go next on this one. The script is supposed to use a nested loop, but what goes in what loop to reverse the order of the user's input? I asked my teacher for help, but he told me "Ask someone else." I asked another seasoned programmer in my class, who was just about as stumped as I was, so I went back to my teacher. "Well, ask another person" he replied. And can you believe this guy has a Master's Degree of Computer Science? So I'm asking you guys: the community. I hope someone will be able to help me. On top of that, I have to help and tutor two special education students in my class on this kind of stuff during class, and they can't get the project done until I get it done, as they learn from analyzing and copying my work (which my teacher told me to do). They get upset when they have nothing to code, and they end up goofing off the entire period, or using it as a study hall. I need to get them back on track, so we can move on to the next project. Please help me with this code - it would be greatly appreciated. Thank you! Hey everyone! I am pretty new to JS and I am having a problem figuring this loops structure out - any help would be appreciated. I am trying to add a password to an html page via an external JS file. (I know this isn't an ideal solution for securing a page - I am just trying to use this for trying to understand loops.) What I am trying to do is prompt the user to enter a password before the html page loads. If the password is correct they can enter the page. If they guess wrong the user is looped back to a prompt box to try again. If they fail 3 times they should be told via an alert box and sent off somewhere else. I have tried using a for & do while loop and was unsuccessful. I think this is the best way to go. This is what I have so far: Code: var password = prompt('All women a ',' '); var pass1 = "Psycho"; var counter = 0; if (counter < 3) { if (password = pass1) { alert('Password Correct! Click OK to enter!'); counter++ } else { alert("Password Incorrect!!!"); window.location="Lab5Part2.html"; } } else { alert("You have failed 3 times!"); window.location="http://www.google.com"; } |