JavaScript - I Would Appreciate Some Quick Help On Making A User Prompted Diamond
This is what I have so far.
Rhombus The topRight/downRight are fine...But, I have no idea how to flip and bring to center the topLeft/downLeft. I would appreciate some quick guidance. Here is my javascript. var treeHeight; var firstColor; var secColor; function getInput(){ treeHeight = prompt("Enter height of the rhombus", ""); firstColor = prompt("Enter first color", ""); secColor = prompt("Enter second color", ""); } function topRight(myheight, color1,color2){ var mydesign="*"; for(i=0;i<myheight;i++){ var lineColors="<p>"; for (j=0; j<=i;j++){ if (j%2){ lineColors +="<span style='color:" +color1 +";'>" + mydesign + "</span>"; } else { lineColors +="<span style='color:" + color2 +";'>" + mydesign + "</span>"; } } lineColors +="</p>"; console.log(lineColors); document.write(lineColors); } } function downRight(myheight, color1, color2){ mydesign ="*"; for (i=myheight;i > 0;i--){ var lineColors="<p>"; for (j=0;j<i;j++){ if (j%2){ lineColors +="<span style='color:" +color1 +";'>" + mydesign + "</span>"; } else { lineColors +="<span style='color:" + color2 +";'>" + mydesign + "</span>"; } } lineColors +="</p>"; console.log(lineColors); document.write(lineColors); } } function topLeft(myheight, color1,color2){ var mydesign="*"; for(i=0;i<myheight;i++){ var lineColors="<p>"; for (j=0; j<=i;j++){ if (j%2){ lineColors +="<span style='color:" +color1 +";'>" + mydesign + "</span>"; } else { lineColors +="<span style='color:" + color2 +";'>" + mydesign + "</span>"; } } lineColors +="</p>"; console.log(lineColors); document.write(lineColors); } } function downLeft(myheight, color1, color2){ mydesign ="*"; for (i=myheight;i > 0;i--){ var lineColors="<p>"; for (j=0;j<i;j++){ if (j%2){ lineColors +="<span style='color:" +color1 +";'>" + mydesign + "</span>"; } else { lineColors +="<span style='color:" + color2 +";'>" + mydesign + "</span>"; } } lineColors +="</p>"; console.log(lineColors); document.write(lineColors); } } Similar TutorialsHi, I'm new here, and I'm a programming newb but am very interested in learning and possibly pursuing programming in the future. As such, I'm taking an intro to Javascript class at my university, and our homework is to make a function that when called upon makes a diamond out of *'s. It is supposed to do so by prompting a user for an int and then makes a diamond shaped object with the inputted number of stars in the middle of the diamond. an example of what this would look like (if a user entered in "5" to the prompt): *<br> ***<br> *****<br> ***<br> *<br> I am not sure how to set up this for loop, and have been trying so many different codes and have come nowhere close. Any help or insight would be so much appreciated. I have a form that has several dependant drop down boxes and copies all of the selections to a text box so you can paste the results to another location. I am using this in training to simulate the selections they will make in the actual system. I would like for the last selection to be a link instead of another drop-down box so that I can direct them to more information (a step by step) based on their selections. I am including a scaled down version of my code below. It actually has 8 possible selections for code 1 and 83 for code 6. I have looked at http://www.outfront.net/tutorials_02/faq.htm#DropDown but am not sure how to adapt it to work with the dependant boxes. Any help would be greatly appreciated! Code: <html> <head> <script type="text/javascript"> <!-- var arrItems1 = new Array(); var arrItemsGrp1 = new Array(); arrItems1[1] = "Selection 1"; arrItemsGrp1[1] = 1 var arrItems2 = new Array(); var arrItemsGrp2 = new Array(); arrItems2[12] = "Selection 1"; arrItemsGrp2[12] = 1 var arrItems3 = new Array(); var arrItemsGrp3 = new Array(); arrItems3[42] = "Selection 1"; arrItemsGrp3[42] = 12 var arrItems4 = new Array(); var arrItemsGrp4 = new Array(); arrItems4[133] = "Selection 1"; arrItemsGrp4[133] = 42 var arrItems5 = new Array(); var arrItemsGrp5 = new Array(); arrItems5[244] = "Selection 1"; arrItemsGrp5[244] = 133 var arrItems6 = new Array(); var arrItemsGrp6 = new Array(); arrItems6[500] = "http"; arrItemsGrp6[500] = 244 function selectChange(control,nu){ var frm=control.form; var sel=frm['Choice'+nu]; var iary=window['arrItems'+nu]; var gary=window['arrItemsGrp'+nu]; var cnt=1; while (frm['Choice'+cnt]){ if (cnt>=nu){ while (frm['Choice'+cnt].firstChild){ frm['Choice'+cnt].removeChild(frm['Choice'+cnt].firstChild); } } cnt++; } var myEle=document.createElement("option"); myEle.appendChild(document.createTextNode("[SELECT ONE]")); myEle.setAttribute("value","0"); sel.appendChild(myEle); for (var x = 0 ; x < iary.length ; x++ ) { if ( gary[x]==control.value ) { myEle = document.createElement("option"); myEle.setAttribute("value",x); myEle.appendChild(document.createTextNode(iary[x])); sel.appendChild(myEle); } } } // --> </script> <script language='Javascript'> function doact(d) { var doc = eval("document.form."+d); cp = doc.createTextRange(); doc.focus(); doc.select(); cp.execCommand("Copy"); } function FP_popUpMsg(msg) {//v1.0 alert(msg); } </script> <script language='Javascript'> function listChoices() { var textStr=''; var aSel=document.getElementsByTagName('select'); for(var i=0; i<aSel.length; i++) { if(aSel.length>1) { textStr+=aSel.name+": "+aSel[aSel.selectedIndex].text+","; } } document.form.text1.value=textStr; } </script> </HEAD> <BODY> <form name=form> <div align="center"> <table border="2" width="790" id="table1" bordercolor="#64367C"> <tr> <td width="778" align="left" colspan="2"> </td> <tr> <td width="552" align="left"> <font size="2" face="MS Sans Serif"> Choice 1:<font size="2" face="MS Sans Serif"> <select id="Choice0" name="Choice0" onchange="listChoices(); selectChange(this, 1);"> <option value="0" selected>[SELECT]</option> <option value="1">Selection 1</option> </select></font></font></td> <td width="220" align="center" onclick="FP_popUpMsg('More Info')"> <font face="MS Sans Serif" size="2" color="#FF0000">*</font><font face="MS Sans Serif" size="2" color="#0000FF"> <u> Tell me more</u></font></td> <tr> <td width="552" align="left"> <font size="2" face="MS Sans Serif"> Code 2: <select id="secondChoice" name="Choice1" onchange="listChoices(); selectChange(this, 2); "></select></font></td> <td width="220" align="center" rowspan="5"> <TEXTAREA name="text1" cols="24" rows="5"> Selections will populate here. </TEXTAREA><input onclick="doact('text1')" type="button" value="Copy"> </td> </tr> <tr> <td width="552" align="left"> <font size="2" face="MS Sans Serif"> Code 3: <select id="thirdChoice" name="Choice2" onchange="listChoices(); selectChange(this, 3);"></select></font></td> </tr> <tr> <td width="552" align="left"> <font size="2" face="MS Sans Serif"> Code 4: <select id="fourthChoice" name="Choice3" onchange="listChoices(); selectChange(this, 4);"></select></font></td> </tr> <tr> <td width="552" align="left"> <font face="MS Sans Serif" size="2"> Code 5: </font> <font size="3" face="Courier"> <select id="fifthChoice" name="Choice4" onchange="listChoices(); selectChange(this, 5);" size="1"></select></font></td> </tr> <tr> <td width="552" align="left"> <p><font face="MS Sans Serif" size="2"> Code 6: </font> <font size="3" face="Courier"> <select id="sixthChoice" name="Choice5" onChange="listChoices(); selectChange(this, 6); alert('Reminder') " size="1"></select> </font></p></td> <tr> <td width="552" align="left"> <font face="MS Sans Serif" size="2"> Link: </font> <font size="3" face="Courier"> <select id="seventhChoice" name="Choice6"></select></font></td> <td width="220" align="center"> <font size="2" face="MS Sans Serif"> <a target="_blank" href="reference.htm">Show the Full Spreadsheet</a></a></font></td> </table> </div> </form> </body> </html> ok so im making a runescape private server and i have all the files and i compile and i only get 1 error. witch is the following. http://imageshack.us/content_round.p...upload&newlp=1 can anyone help me out pleasE? Hey guys, I am very VERY new to javascript and while trying to do some simple validating I got stuck and am in a complete loss. Heres my code: Code: <html> <head> <title>Tareas | Numero 4</title> <link rel="stylesheet" type="text/css" href="style.css" /> <script language="javascript" type="text/javascript"> function verify() { total = "Te faltaron los siguientes Campos por llenar: \n"; nombre = document.getElementById("txtnombre"); if (nombre.value == "") { total = total + "\nnombre"; } apellido = document.getElementById("txtapellido"); if (apellido.value == "") { total = total + "\napellido"; } if (total == "Te faltaron los siguientes Campos por llenar: \n") { return true; { else { alert(total); return false; } } </script> </head> <body> <center><h3>Formulario de registracion</h3></center> <div id="formulario_overall"> <form method="post" onsubmit="return verify();" action="/"> <div id="formulario_left"> Nomb <br /> <br /> Apellido: <br /> <br /> Clave: <br /> <br /> Confirmacion de Clave: <br /> <br /> Edad: </br> <br /> <br /> Sexo: </br> <br /> Ciudad: </br> <br /> </div> <div id="formulario_right"> <input type="text" name="nombre" id="txtnombre" /> <br /> <br /> <input type="text" name="apellido" id="txtapellido" /> <br /> <br /> <input type="password" name="p_1" id="p1" /> <br /> <br /> <input type="password" name="p_2" id="p2" /> <br /> <br /> <input type="text" name="age" id="age" /> <br /> <br /> <input type="radio" name="sex" id="sex" /> Femenino<br /> <input type="radio" name="sex" id="sex" /> Masculino<br /> <input type="text" name="city" id="city" /> <br /> <br /> </div> <div id="formulario_bottom"> Terminos De Uso: <textarea rows = "4" cols = "37" readonly="readonly"> Accepto que voy a darle +20 puntos a Daniel Martinez. Accepto que voy a darle +20 puntos a Daniel Martinez. Accepto que voy a darle +20 puntos a Daniel Martinez. Accepto que voy a darle +20 puntos a Daniel Martinez. </textarea><br /> <div><input type="radio" name="terms"> Accepto <input type="radio" name="terms" /> No Accepto</div> <br /> <center><input type="submit" value="Submit" /> <input type="reset" value="Limpiar" /></center> </form> </div> </div> </body> </html> Hope you guys can help me out :/ I just feel like I am doing something totally wrong. Ok, this might sound stupid but I swear, it's about to drive me crazy. how does one check whether or not a javascript "global" variable is undefined that will work with IE? I've tried each variation of code and checked countless forums: Code: if (saved == undefined || saved == null) { alert('saved'); saved = new Array(); } returns no error and nothing happens Code: if (saved == 'undefined') { alert('saved'); saved = new Array(); } -- returns error = saved is null or not an object Code: if (typeof(saved) == undefined) { alert('saved'); saved = new Array(); } returns same as above help me please, I'm confused more then anything. the link is also: http://doodlekins.hcents.com/designer Basically the if statement isn't returning true and nothing on the inside of it is ever happening. I know that global variables are properties of the window object... so does that mean that local variables are properties of the function they belong to? And does that mean that functions are methods of the window object and that nested functions are methods of the function they belong to?
Hi all, This is a quickie. I'm a JavaScript newbie. I have had a crack programming with it but I need some questions answered to help my understanding. Please tell me the convention that governs the use of "" and '', because so many articles that I am finding in my learning journey are using them interchangeably and it is so confusing. For instance, but not limited to, take the id and value tags of an <input type=... of whatever. Is it best to use '' or "" for the labels you give? What is the convention governing the use of a ; (semicolon) because so many people use one where others do not. I'm under the impression it is an EOL terminator like in Bash, right? So it goes after declaring variables or after something within an if statement perhaps? Thanks QF Hi, I have the below code, but got a problem with it. The problem is, if you click Test 1, then Test 2 you have to click Test 2 twice, this also repeats for Test 3, 4 and 5. It is the same with onclick. I presume the problem is in the javascript code, but not sure where to start. Can anyone help <html> <head> <title>Test JS</title> <script language="javascript"> <!-- var state = 'none'; function showhide(layer_ref) { if (state == 'block') { state = 'none'; } else { state = 'block'; } if (document.all) { //IS IE 4 or 5 (or 6 beta) eval( "document.all." + layer_ref + ".style.display = state"); } if (document.layers) { //IS NETSCAPE 4 or below document.layers[layer_ref].display = state; } if (document.getElementById &&!document.all) { hza = document.getElementById(layer_ref); hza.style.display = state; } } //--> </script> </head> <body> <p><a href="javascript:showhide('sect1');">Test 1</a></p> <div id="sect1" style="display: none;">Test 1 content</div> <br><br><br> <p><a href="javascript:showhide('sect2');">Test 2</a></p> <div id="sect2" style="display: none;">Test 2 content</div> <br><br><br> <p><a href="javascript:showhide('sect3');">Test 3</a></p> <div id="sect3" style="display: none;">Test 3 content</div> <br><br><br> <p><a href="javascript:showhide('sect4');">Test 4</a></p> <div id="sect4" style="display: none;">Test 4 content</div> <br><br><br> <p><a href="javascript:showhide('sect5');">Test 5</a></p> <div id="sect5" style="display: none;">Test 5 content</div> </body> </html> I am new to java and tried writing the code for practice but it doesn't seem to work <html> <Head> <title>Discount</title> <script language ="Javascript"> <!-- function CalculateBalance(numItems,totPrice,discount) { var balance; balance = (1 - discount)*totPRice; alert ('Your balance is $'+balance +' Thank You.'); document.write("<br>YOu bought "+ numItems+" items for $"+totPrice); document.write("<br>Your balance is $"+ balance+" your discount was"+discount*100+"% Thank you"); } //--> </script> </head> <script language ="Javascript"> <!-- var discount; var numItems = parseInt(prompt('HOw many time did you buy [ >=12 is 20% and >= 6 is 10% discount]',"0")); alert ('You bought '+numItems +' items.'); document.write("You bought "+ numItems+" items."); var totPrice = parseFloat(prompt('The total price that you paid was',"0.0")); if(numItems >= 12) {discount = .2;} else if (numItems >=6) {discount+ .1} else {discount = 0;} CalculateBalance(numItems,totPrice,discount); //--> </script> </html> It only prints to the screen the number of items I bought Urghh I've always done it this way but it's nagging me. Is there a better way of checking if a value is equal to 1 or 2 or 3 than doing it this way. Code: if(var === Cat || var === Dog || var === Chicken || var === Frog) Not working code ^ lol Cheers guys Don't even know where to post this as I have never thought about it; I've just made my game have a image upload script in, and a album showing the users images. How could I make have a link saying "Copy Link" that if clicked will copy the picture url to clip board. I've seen places like w3schools use in but not as tuts though. Please this will really help, desplayin the link is ugly EDIT: I've found the following code but I don't understand how I turn it into a link or button. Code: <script> window.clipboardData.setData('text','This has been copied to your clipboard.'); </script> I tried posting this: <button type="button" onclick="JavaScript:alert('Let's assume.....')"> <img src="question.jpg" alt="Click here" /> <br />Click for Answer!</button> and it shows the button with the picture, but I am unable to click it. Can you please help me? Thank you in advance. I want to create dynamic Select option in form, I want that whenever user clicks on add member button then new row will get added & i have done that by taking help of DOM createElement method & I want that by using same, I want to create select option drop down list.
I put the jquery script into my subdirectory. In the header which one is correct: Code: <script type="text/javascript" src="../jquery/jquery.js"></script> or Code: <script src="../jquery/jquery.js"></script> And there is this code: do I put this in the body and enclose it with the <script>tag? Code: $(function(){ // set interval for 5 minutes setInterval(function(){ $.ajax({url: "keep-alive.php"}); }, 300000); }); I have a twitter widget at this side http://1905.gs/blog on the right sidebar. At the bottom of the widget there is the follow me link. I would like to embed a follow me "button" which I have created the script for: The button script: <a href="https://twitter.com/1905GS" class="twitter-follow-button" data-show-count="false" data-lang="tr">Takip et: @1905GS</a> <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script> And here is the current javascript link: http://www.1905.gs/blog/wp-content/p...tter-widget.js How I am trying to make it look like: http://a1202.hizliresim.com/u/d/2nryy.jpg thank you very much for your help, It's been many years since I've done simple javascript and html. I was wondering if javascript would be the language of choice for this project. I would like a simple matrix with individuals on the left column, and locations on the top row. Clicking in any cell turns on a green dot/box/circle or whatever. Clicking on a green whatever makes it disappear. Even more handy would be to make each cell in a row mutually exclusive of the others; turn any cell on and the other cell turns off. If anybody has thoughts or advice, I would greatly appreciate it. This is intended to be a tool for our intranet for tracking the location of key people. Thankfully, Russ using jquery and cookie plugin. i made a popup window. when the user clicks on a check box the window closes, forwards them to a new page, and then sets a cookie. i need it so that when they go back to the original page (where the popup came from) if the browser detects the cookie then the popup does not occur. I do not know why this does not work because when I alert the value of the cookie out, it gives me the correct number. something must be wrong in my logic ? code on the base page. Code: <script type="text/javascript"> var test123 = $.cookie('FBCheck'); if ( test123 != 1212){ function popup(Site) { window.open(Site,'PopupName','toolbar=no,statusbar=no, location=no,scrollbars=no,resizable=no,width=350,height=500') } } </script> code on popup (both files are in same directory) Code: $(document).ready(function() { $("#Cbox").click(function() { window.open ("http://www.google.com", "Google"); window.close(); $.cookie('FBCheck', '1212', {expires: 365, path: '/'}); }); }); The jquery source is installed as is the plugin. Thanks so much for your help in advance! can I have a function and a variable be the same name in an object for instance Code: function someObject(){ this.canDoSomething;//a boolean variable function canDoSomething(){ //set this.canDoSomething; return this.canDoSomething; } } or will this be a naming conflict? thanks I found this "game" that helps you practice regexp. I'm stuck on this one: |