JavaScript - Loops, Arrays And Attributes
I am looking to get a loop which runs through a series of divs (each with an attribute called "position" followed by 5 comma separated values).
for each of these divs i need the 5 comma separated values (from position) to be assigned to variables. I have the rest of the code sorted out i just cannot get the original variables. Examples: divs look like this... Code: <div position="100,100,50,50,1"></div> There are no limits on the number of these divs but there will never be 0. What i want is something to look like this. For each div, var s = string of attribute (position) values (output:a,b,c,d,e) split string to create var a = a var b = b var c = c var d = d var e = e I from those 5 vars can do what i need. and i know that vars a,b,c,d,e,s will all be overwritten in when it comes to the next div... that is planned. Similar TutorialsI 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. How does my array look so far? thanks I think so what i was supposed to do was insert a script element that contains the function amountTotal() then add commands to the function such as 1 declare variable named total, set intial value to 0 2 create a FOR LOOP that loops all values in amount array. add current value of array item to value of total variable 3 when completed return value of total variable This is what I came up with tell me if this makes sense Thanks Quote: title>The Lighthouse</title> <link href="lhouse.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="list.js"></script> <script type="text/javascript"> function amountTotal() { totalAmount=0; for(var i=0; i<amountTotal.length; i++){ total+=amount(i); { return total; } </script> </head> Does this seem right or is my format all wrong? if so what should i have instead? thanks I've now got to form an average of snowfall inputs, taken from looped prompts, however I'm not allowed to use arrays or functions... Almost every example I see uses arrays, such as this one he http://www.codingforums.com/showthread.php?t=4313 Is it possible to not use arrays to form the average? Please describe how to do this in general terms, as was highlighted in that link ^^^ I want to learn, not copy, although one can be derived from the other... What I haveso far, assume all vars have been announced. Code: for (var d=1; d<=numofinputs; d=d+1) { input = prompt("Enter a data input" + d) } Is it possible I'm attempting this in too general a manner? ie, running before I can walk. Hello everyone I am having trouble with a project i am supposed to be doing which is to turn structured English into coding joined with the code i am about to post !! This is the code i have written so far that works: var contestantNamesArray = ['Tom and Nazia', 'Pat and Dan', 'Sandra and Kofi', 'Ian and Adele', 'Paul and Costas']; var judgesPointsArray = [2,1,5,4,3]; var audiencePointsArray = [4,5,2,3,1]; var combinedPointsArray = new Array (5) for (var couple = 0; couple < combinedPointsArray.length; couple = couple + 1) { combinedPointsArray[couple] = judgesPointsArray[couple] + audiencePointsArray[couple]; } var maxCombinedPoints = 0; for (var couple = 0; couple < combinedPointsArray.length; couple = couple + 1) { if (combinedPointsArray[couple] > combinedPointsArray[maxCombinedPoints]) { maxCombinedPoints = couple; } } document.write('The maximum number of points was ' + combinedPointsArray[maxCombinedPoints] + '<BR>'); document.write('The couple(s) scoring the maximum were' + ':' + '<BR>'); Now with that code there i have just posted, I am supposed to take this structured English below and combine them together but cannot work out how to link or code it to get it to work. write out a heading for the list of couples scoring the maximum declare a variable to keep count of how many couples scored the maximum value and initialise it to zero for each couple if this couple scored the maximum write out the couple's names increase the count of couples who scored the maximum value end if if a dance-off is required write out that a dance-off is required else write out that a dance-off is not required end if end for I have tried myself but i am stuck at how to link the contestantNamesArray with the rest of the code in order to be able to display the couples who scored the maximum points and store it in a new variable and then write out the names. Sorry if i have posted wrongly this is my first time and i am a new learner to JavaScript trying to learn basics. Thank you anyone in advance and if you need any further information i will provide anything you need. Gary I am having an issue with this script I wrote. Actually it works the way it is now, but not the way I want it too. This is a random raffle ticket number generater. The guys at the fire department where talking about selling 300 tickets and discussing how they were going to select and call the numbers. It got me thinking and inspired to start messing around with javascript again. It all starts with index.html and a form w/ a button and textarea. When a user clicks the button it will generate a random number and insert it into the textarea. This is accomplished by the Generate(); function that is in Genny.js an external js file. Code: <h2>Raffle Ticket Number Generator</h2> <form name="theform"> <input type="button" name="pickNumber" value="Pick a Winner" onclick="Generate();" /> <br /><br /> <textarea cols="40" rows="25" name="winnersCircle">Winning Numbers Will Display Here! </textarea> </form> This much works just fine. Now onto Genny.js Code: //initialize counter and array count = 1; winners = new Array(); function Generate(){ //generate a random number from 0-300 var random_number = Math.floor(Math.random()*301); //checks output of Math.random() against winners array to see if number has been used already for (i = 0; i < winners.length; i++ ) { if ( winners[i] == random_number ) alert("I am so sorry... we have accidently drawn a duplicate number! Please pick again."); } //add the number to the array winners[count] = random_number; //increment the counter count++; //display the stored random number document.theform.winnersCircle.value = winners.join("\n"); } This much works...somewhat! It generates the random number and checks the winners array to see if it is already used. If it wasn't used it adds the number to the array, increments the counter, and then displays the number in the textarea of the form, as it should. If the number was used it alerts the user, once the user clicks the button to accept the alert it carries on with the script and adds it to the array again and also displays it. This is not what I want it to do. If the number was used I do not want it added to the array or displayed. I would also like it to regenerate another number without the alert. The alert was wrote in to assist me in checking to see if it was finding a duplicate number, thats all. As an extra, is there a way to also add a numbered list to the results. To show the sequence of the ticket draw. I have messed with this for days and rewrote it over and over. I have used different loops and conditional operators to try and solve this problem. But to no avail. Here I am, asking not for the answer but a push in the right direction. Any help would be great, this is becoming an obsession trying to make it work. The code above is the last attempt at this point. Everything else has returned no values or just errors. Thanks in advance! I need to loop the alphabet and numbers 0-9 to initialize a few thousand arrays. This is for my site and is truly needed. http://www.thefreemenu.com I currently have every array written out and it takes up to much space in my .js file. The majority of my variables are empty but necessary and need to be there (including empty) for my site to work properly. Question is the last part Here's where I'm at. Code: var NewVarLetterOrNum = "a"; eval("_oneofseveralnames_" + NewVarLetterOrNum + "='this part works';"); alert(_oneofseveralnames_a); This creates the variable _oneofseveralnames_a='this part works' Code: var newArrayLetterOrNum = "a"; eval("_oneofseveralnames_" + newArrayLetterOrNum + "= new Array();"); alert(_oneofseveralnames_a) This creates the Array _oneofseveralnames_a=new Array(); and all the values in the array are null, but, now a variable like _nl_a[1]='something' can be used elsewhere because the array exists. This is all that is necessary for now because I can probably set all the variables to be blank with something like Code: i=1 while(i<=20){ _oneofseveralnames_a[i]="1-20"; i++ } alert(_oneofseveralnames_[20]); So now you have what I came to understand in the first few hours. Now to the hard part : ( I can't make multiple array's dynamically. I dont' know if its because I don't understand loops or arrays or what and its very fustrating. As for any answer you might be so kind as to provide, if you could dumb it down that would be greatly appreciated. Code: var newArray =new Array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z') i=1 while(i<=26){ eval("_nl_" + newArray[i] + "= new Array();"); i++ } alert(newArray[1]) // Is b, but alert(_nl_b) //I can't get _nl_b to exist, I tried everything including taking away the quotes around the letters in every test */ var _nl_a =new Array() var _img_a =new Array() var _h_a =new Array() var _r_a =new Array() var _m_a =new Array() var _yt_a =new Array() var _i_a =new Array() The above arrays are all the array _name_ parts I need but for example, a has 10 parts, a,p2_a,p3_a,.. p10_a. I need 10 pages for each letter of the alphabet and numbers 0-9 and a special all1, p2_all1 ... p10_all1. Overall 2200 arrays that need to be declared. Currently they are all written out. /* Hey there. I want to move a div around a page, and I do this by getting the original top and left values of a div, and then change them. But the problem is getting the original values; I checked online and thought that this would work: Code: var chart = document.getElementById(charDiv).style.top; var charl = document.getElementById(charDiv).style.left; alert('char_t:' + chart + ' char_l:' + charl + 'charDiv:' + charDiv); charDiv is passed into the function (its the id of the div I want to move). I know that charDiv has a value by looking at the values of the alert() statement, but the values of chart and charl are empty. The alert simply outputs char_t: char_l: charDiv: charOne any help would be appreciated Hi Guys, I'm new at JS. I need to remove TR elements from parent table but the problem is there are no table ID/Name Is it possible to perform it? Please see attach - i need remove red marked block... what scrip i have to use if i will put it to the green block? Thank you. how about getting the attributes of the a tag? href and title and the innerhtml (actually the innerhtml has space on both ends)
Hi everyone, I'm currently in the process of making a spreadsheet like webpage and it all working fine... However I have been using setAttribute and removeAttribute in order to dynamically change a table cells onclick property. This of course does not work in IE7 etc and I've been banging my head against a brick wall trying to come up with a solution that will work in all browsers but I just can't seem to get it to work with using methods such as... Code: document.getElementById(myElementId).onclick = scriptToRun; document.getElementById(myElementId).attachEvent('onclick',scriptToRun); I get all sorts of not implemented, type mismatch errors when I try to use the above. Below is the setAttribute code which works. Code: document.getElementById("task_" + colName + studentId).setAttribute("onclick","showTaskDropDown('task_" + colName + studentId + "','" + studentId + "','" + colName + "','" + value + "','" + maxValue + "','" + trafficMaxValue + "','" + taskNumber + "')"); If anyone can see why the other methods aren't working and can provide a solution I'll be extremely greatful! I attempting to set attributes for all tags of a particular type.... I have a bunch of thumbnails <img> tags; when I wand over them I would like to show the corresponding large image with a script but the tags require onMouseOver events. I really don't feel like adding a bunch of onMouseOver="myShowScript" attributes to every img tag manually... my scripts aren't working... partly because I'm a newbie... I'm sure there is some fundamental concept about java and html I don't get... here's ONE of the versions that doesn't work.. I've tried a few things but I'm open to scrapping everything for a better way... I appreciate any direction you can offer... Code: function addAtts(){ var numberOf = document.getElementsByTagName("img"); for(i = 0; i < numberOf.length; i++){ numberOf[i].onMouseOver="myShowScript()"; } } hello Sir/Mam i have a piece of code here that creates a dynamic form.. Code: <script type='text/javascript' language='javascript'> <!-- function createTextbox(){ var textboxtag = document.createElement("input"); textboxtag.setAttribute("name","username"); document.getElementById("form1").appendChild(textboxtag); } --> </script> <body> <div id='div1'> <button name='textbox' onclick='createTextbox()'>Textbox</button> </div> <div id='div2'> <form id='form1' action='#' method='post'> </form> </div> </body> this code sets the "name" attribute to "username" automatically.. my problem is how to set the name attribute manually by the user after the dynamic textbox is created.. just like in visual basic where after you create a form e.g button or textfield, theres a side pane where you can change attributes like name, value, etc.. tnx for the time reading my post..sorry for my poor explanation of the problem..im new in javascript and trying to learn it all by myself.. Hi, I'm not even sure if that's the issue here, but I've isolated it and all the other code is working, so what I'm thinking is that if this: Code: function togglePoly(poly_num) { if (document.getElementById('poly'+poly_num)) { if (document.getElementById('poly'+poly_num).checked) { gpolys[poly_num].show(); } else { gpolys[poly_num].hide(); } } } function createClickablePolyline(poly, html, label) { gpolys.push(poly); var poly_num = gpolys.length - 1; if (!html) {html = "";} else { html += "<br>";} if (html) { GEvent.addListener(poly,'click', function(point) { if (!point) point = poly.getVertex(Math.floor(poly.getVertexCount()/2)); map.openInfoWindowHtml(point,html); }); } label = "<a href='javascript:GEvent.trigger(gpolys["+poly_num+"],\"click\");'>"+label+"</a>"; // add a line to the sidebar html sidebar_html += '<input type="checkbox" id="poly'+poly_num+'" checked="checked" onclick="togglePoly('+poly_num+');">' + label + '<br />'; } document.getElementById("sidebar").innerHTML = sidebar_html; works here to hide/show a line, then this: Code: function show(category) { for (var a=0; a<gpolylines.length; a++) { if (gpolylines[a].mycategory == category) { gpolylines[a].show(); } } for (var i=0; i<pts.length; i++) { if (pts[i].mycategory == category) { pts[i].show(); } } } function hide(category) { for (var a=0; a<gpolylines.length; a++) { if (gpolylines[a].mycategory == category) { gpolylines[a].hide(); } } for (var i=0; i<pts.length; i++) { if (pts[i].mycategory == category) { pts[i].hide(); } } } // this variable will collect the html which will eventually be placed in the sidebar function togglePoly(category) { if (document.getElementById(category)) { if (document.getElementById(category).checked) { show(category); } else { hide(category); } } } function createClickablePolyline(poly, html, name,category) { gpolys.push(poly); var poly_num = gpolys.length - 1; var category = lines[a].getAttribute("category"); midLineArrows(pts, category); GEvent.addListener(poly,'click', function(point) { if (!point) point = poly.getVertex(Math.floor(poly.getVertexCount()/2)); map.openInfoWindowHtml(point,html); }); // add a line to the sidebar html label = "<a href='javascript:GEvent.trigger(gpolys["+poly_num+"],\"click\");'>"+label+"</a>"; sidebar_html += '<input type="checkbox" id="'+category+'" checked="checked" onclick="togglePoly('+category+');">' + label + '<br />'; } document.getElementById("sidebar").innerHTML = sidebar_html; should work here to show/hide lines and arrows the difference of course being that the first code uses poly_num, which is taken directly from the Code: var poly_num = gpolys.length - 1; code (because it only needs to show/hide one line at a time) whereas the second uses the xml attribute "category" from here Code: var category = lines[a].getAttribute("category"); because it's attempting to hide and show a line with arrows on it (the arrows being in the pts array), both of which share the category attribute. It's not throwing up any major errors, but it's not working, either... any suggestions would be great... thanks in advance... Hi All I have a piece of script which makes a div slide out from the side of the screen with information on it. I can change the innerHtml etc no problem, but i have a problem with change .style attributes dynamically. My code: Code: var mystring = "height:500px"; var keyVal = mystring.split(":") var slidingDiv = document.getElementById('slidingDiv'); slidingDiv.style.keyVal[0] = keyVal[1]; As you see above i get a value which i need to split() to get the key and value to use. So what i would like to see is: Quote: slidingDiv.style.height = 500px; But it does not work, as there is no such function as slidingDiv.style.keyVal[0]; How do i change this? I hope I've explained this thoroughly enough. Please ask if i need to explain further. Regards Marinus how to search through siblings for shared attributes I have a a long list of links and I suppose Im going to apply a number of classes to each one [describing a number of attributes for each] and I want to do a conditional search probably in javascript/jquery so that when i hover over one of the links I highlight its relatives - those that have the same attributes. What Im having trouble wrapping my head around is the idea of classes to ID these custom attributes. The attributes are coming from a database converted to XML. In my Javascript I essentially want to say that for each link should the user mouseover or mouseclick for each of its sibling links if its sibling link share its attributes style or highlight these compliant siblings a certain way how do I do the 'if statement' without spelling out every possible attribute entry? I know in plain OOP Java how I could test for this but in that scenario I have access to these entries as fields in an object's instantiation. Help? thanks so much in advance I'm not really much of a javascript programmer, but I occasionally use javascript that I've found here and there. But I'm unable to find anything that helps me in what I'm trying to do now. I regularly use a snippet of code that pops up a small window to display an image or a very small html file. Using the window.open() function, I'm able to disable scrolling, resizing, etc., and size it to my needs. I'll have a window.close link somewhere on the page. But in my current project, my customer's page has several links related to other companies. When you click on the link, an that company's ad pops up in a small window. At this point, the viewer can simply close the window, or they should be able to click on the ad and be taken to that company's website. I'm able to have it close the window and open that new url in the parent browser window, but my website customer doesn't want their site to go away. They want the new company's website in a new window. Or I can simply NOT close the popup window, but now the new company's website is in a relatively small browser window, unable to scroll, resize, etc. Is there a way for me to somehow modify an existing window with an onclick directive - something similar to the window.open() function, OR open a new browser window with window.open() AND close the popup window? If I haven't made myself clear, let me know and I'll try to explain myself better. Thanks in advance for any help. Which is considered best practice? Code: <div onmouseover="doThis();"> myDiv.onmouseover = doThis; myDiv.addEventListener("mouseover",doThis,false); ...or something else? Hi, I'm having trouble with some flash players that don't abide by the style attribute of the div they're created in using Javascript. When the flash-players' source is hard-coded into the page source they render fine, but the more players, the more bloat as you can see in the source of the original page. Any help? Example: http://mcbryanmd.webs.com/Playertest.htm Original Page with old code: http://mcbryanmd.webs.com/ The problem code: Code: <script type="text/javascript"> function clv(obj){ var strst="http://static.livestream.com/scripts/playerv2.js?channel="; var strnm=obj; var strnd="&layout=playerEmbedWide&backgroundColor=0x000000&backgroundAlpha=.5&backgroundGradientStrength=0&chromeColor=0x000000&headerBarGlossEnabled=true&controlBarGlossEnabled=true&chatInputGlossEnabled=true&uiWhite=true&uiAlpha=0.5&uiSelectedAlpha=1&dropShadowEnabled=true&dropShadowHorizontalDistance=10&dropShadowVerticalDistance=10&paddingLeft=0&paddingRight=0&paddingTop=0&paddingBottom=0&cornerRadius=3&backToDirectoryURL=null&bannerURL=null&bannerText=null&bannerWidth=320&bannerHeight=50&showViewers=true&embedEnabled=false&chatEnabled=true&onDemandEnabled=false&programGuideEnabled=false&fullScreenEnabled=false&reportAbuseEnabled=false&gridEnabled=false&initialIsOn=true&initialIsMute=true&initialVolume=10&contentId=null&initThumbUrl=null&playeraspectwidth=4&playeraspectheight=3&mogulusLogoEnabled=false&width=100%&height=100%&wmode=window"; var clsrc=strst + strnm + strnd; var pstrm=document.createElement('script'); document.getElementById('pcont').appendChild(pstrm); pstrm.setAttribute("type","text/javascript"); pstrm.setAttribute("src", clsrc); } </script> <button onclick="clv('random0')" onmouseover="this.style.color='#00FF00'"onmouseout="this.style.color='#FFFFFF'">random0</button> <button onclick="clv('random1')" onmouseover="this.style.color='#00FF00'"onmouseout="this.style.color='#FFFFFF'">random1</button> <button onclick="clv('random2')" onmouseover="this.style.color='#00FF00'"onmouseout="this.style.color='#FFFFFF'">random2</button> <div id="pcont" style="margin-left:250px;display:;position:fixed;top:40px;right:0px;left:0px;bottom:0px;background-color:#CCCCCC;"></div> 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"; 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 |