JavaScript - Javascript Username Generator
Hello.
I'm new here and learning JavaScript. Could you help me to write very simple script to auto generate user name ? From any letters. Min 6 - Max 10. Like: "jgFJFJ" "KGHGyvk" etc. Please help. Similar TutorialsOk, so I decided to make an Experience Generator for my site. I started simple by making one that uses a prompt. First it prompts for your level, then it multiplies it by using a random number function. This code below. Code: <html> <head> <title>Experience Generator</title> <script type="text/javascript"> var A= Math.round(Math.random()*100); var B= prompt('Place your Level Here'); function Expearned() { document.write(Exp=B*A); document.write(" Experience Points Earned"); } </script> </head> <body> <a href="javascript:Expearned()">Experience Calculator</a><br /> </body> </html> Then, I thought... I don't like using prompts. So, how about using text inputs and buttons instead. I then created this code. Code: <html> <head> <title>Experience Generator</title> <script type="text/javascript"> var A= Math.round(Math.random()*100); var B= input(); function Expearned() { document.write(Exp=B*A); document.write(" Experience Points Earned"); } </script> </head> <body> <FORM ACTION="#" NAME=LeveltoExp></FORM> Enter Level <INPUT TYPE=TEXT NAME="Enter Level" SIZE=3> <BR><BR> <INPUT TYPE=BUTTON VALUE="Earn Experience" ONCLICK=" Expearned() + 'is ' + ' Experienced Earned'"> <BR><BR> </FORM> </body> </html> BUT this code pulls up and error at the line of var B.. What I am trying to do is pass the form to the var B and then goes on from there to do the Experience Generator. Can anyone Help me???? Hello all, I am enrolled in a class that requires a bit of JS/HTML coding; my final project is to create a simple page representing myself. See example. And yes, that is my teacher. I am allowed to utilize "templates or tools". I am using my macbook, but I have access to school windows computers. Any suggestions on what to use to complete this assignment are greatly appreciated. I'm working on a site with someone else and they would like the username to be entered in a form on a page, then passed to a second page that says 'Welcome [username]'. I am aware of how to do this using var prompts on the SAME page, but what about different pages. I'd also like to know how secure this is? The name is being used in a page (i.e. login.php) and passed to another page (i.e. welcome.html). The person has requested Javascript. How could this be done? If there is a better way to do so, what is it?
I'm having trouble getting two password boxes to work on the same page, which I created using the JavaScript Kit Encrypted Password Generator (http://www.javascriptkit.com/epassword/index.htm). I've used the code that this generator produces, with some modifications as given by cheesebagpipe (http://www.codingforums.com/showthread.php?t=14646). These changes enable the user to press the keyboard's enter key to submit the password (as an alternative to clicking the submit button), and will also refocus the text box and select the text in it if the user enters the wrong password. The code works fine on pages with just one box (e.g. http://www.mistymusic.co.uk/StLuke's.html), but what changes are needed to make two work on the same page? (I'm new to web design and clueless when it comes to JavaScript, which I know isn't the most secure method of password protection, but will do for now). At the moment, on pages with two boxes (e.g. http://www.mistymusic.co.uk/BEAP.html), neither of the boxes work; this appears in the address bar instead: 'http://www.mistymusic.co.uk/BEAP.html?password2=help!' ('help!'=whatever has been entered in the text box). The full code for both boxes is given below. Code: <div id="passwordBoxes"> <div id="password2"> <form name="password1" onsubmit="submitentry();return false;"> <span class="WhiteLogin">Keyboard classes login</span> <input name="password2" type="password" class="AlignedFormBoxes" size="15" /> <input type="button" class="AlignedFormBoxes" value="Login" /> </form> </div> <div id="password1"> <form name="password1" onsubmit="submitentry();return false;"> <span class="WhiteLogin">Community Youth Choir login</span> <input name="password2" type="password" class="AlignedFormBoxes" size="15" /> <input type="button" class="AlignedFormBoxes" value="Login" /> </form> </div> </div> <script> var pass=new Array() var t3="" var lim=6 pass[0]="gc3Gu5uygvU8VDA" pass[1]="aNL6yjrU5AAKyy3" pass[2]="enSaX8glavp54H" pass[3]="WF3XUKEpbbMEx" pass[4]="8Pv7bsEqaIjNdb6b" pass[5]="35Pv7bsEqaIjNdb6" //configure extension to reflect the extension type of the target web page (ie: .htm or .html) var extension=".html" var enablelocking=0 var numletter="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" var temp3='' var cur=0 function max(which){ return (pass[Math.ceil(which)+(3&15)].substring(0,1)) } function testit(input){ temp=numletter.indexOf(input) var temp2=temp^parseInt(pass[phase1-1+(1|3)].substring(0,2)) temp2=numletter.substring(temp2,temp2+1) return (temp2) } function submitentry(){ t3='' verification=document.password1.password2.value phase1=Math.ceil(Math.random())-6+(2<<2) var indicate=true for (i=(1&2);i<window.max(Math.LOG10E);i++) t3+=testit(verification.charAt(i)) for (i=(1&2);i<lim;i++){ if (t3.charAt(i)!=pass[phase1+Math.round(Math.sin(Math.PI/2)-1)].charAt(i)) indicate=false } if (verification.length!=window.max(Math.LOG10E)) indicate=false if (indicate) window.location=verification+extension; else { alert("That wasn't the correct password. Please check that your CAPS Lock key is turned off and try again."); document.password1.password2.focus(); document.password1.password2.select(); } } </script> <script> var pass=new Array() var t3="" var lim=7 pass[0]="Qmsn8tUQZX4T0PC" pass[1]="DUtntGtFhaTppWO" pass[2]="JahI7L4JqbxZrwS" pass[3]="ong1qqnbr9rvV2s" pass[4]="7BlqC2sc8hQ8bWMK" pass[5]="15BlqC2sc8hQ8bWM" //configure extension to reflect the extension type of the target web page (ie: .htm or .html) var extension=".html" var enablelocking=0 var numletter="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" var temp3='' var cur=0 function max(which){ return (pass[Math.ceil(which)+(3&15)].substring(0,1)) } function testit(input){ temp=numletter.indexOf(input) var temp2=temp^parseInt(pass[phase1-1+(1|3)].substring(0,2)) temp2=numletter.substring(temp2,temp2+1) return (temp2) } function submitentry(){ t3='' verification=document.password1.password2.value phase1=Math.ceil(Math.random())-6+(2<<2) var indicate=true for (i=(1&2);i<window.max(Math.LOG10E);i++) t3+=testit(verification.charAt(i)) for (i=(1&2);i<lim;i++){ if (t3.charAt(i)!=pass[phase1+Math.round(Math.sin(Math.PI/2)-1)].charAt(i)) indicate=false } if (verification.length!=window.max(Math.LOG10E)) indicate=false if (indicate) window.location=verification+extension; else { alert("That wasn't the correct password. Please check that your CAPS Lock key is turned off and try again."); document.password1.password2.focus(); document.password1.password2.select(); } } </script> Any help would be a lifesaver - thanks in advance! Hi there... actually i am working on a project "random password generator". What basically is to be done in this project is to generate user password for the username randomly he has provided. Then, this password is to be stored in a text file in the following manner UserName Password ABCD JU12H6 Sdjksj HJudfdsfd Now my problem is that every time I just try to generate a new password, either a new file is made or the heading is rewritten again and again or if I just try to change the variables true and false, then the username and password headings are not printed. Please help. If someone knows how to do this using if-else method then please tell me, how it can be done? The code is attached. Code: <html> <HEAD> <SCRIPT LANGUAGE="JavaScript"> function GetSelectedItem() { chosen = ""; for (i = 0; i <3; i++) { if (document.myform.opt[i].checked) { chosen = document.myform.opt[i].value; } } if (chosen == "") { alert("Choose your password type") exit; } return chosen; } function getPassword(usnm,length,opti) { if(usnm=="") { alert("Enter user name"); exit; } var optsel=GetSelectedItem(); var num = "0123456789"; var alpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; var alphanum = "0123456789abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; var pass = ""; if(length!=5 && length!=6 && length!=7 && length!=8 && length!=9 && length!=10) { alert("Enter password length between 5 and 10"); exit; } else { if (optsel==1) { for(x=0;x<length;x++) { i = Math.floor(Math.random() * 72); pass += alphanum.charAt(i); } } else if (optsel==2) { for(x=0;x<length;x++) { i = Math.floor(Math.random() * 10); pass += num.charAt(i); } } else if (optsel==3) { for(x=0;x<length;x++) { i = Math.floor(Math.random() * 52); pass += alpha.charAt(i); } } WriteToFile(usnm,pass); return pass; } } function WriteToFile(usnm,pass) { try { var fso1=new ActiveXObject("Scripting.FileSystemObject"); var pf1=fso1.OpenTextFile("Password.text",8); //if(pf=='false') //var fso=new ActiveXObject("Scripting.FileSystemObject"); //dspf=fso.OpenTextFile("Password.txt",8,true); //pf.WriteLine("Username\t\tPassword"); pf1.WriteLine(usnm+'\t\t'+pass); pf1.Close(); } catch(err) { var fso=new ActiveXObject("Scripting.FileSystemObject"); pf=fso.CreateTextFile("Password.txt",8,false); pf.WriteLine("Username\t\tPassword") pf.WriteLine(usnm+'\t\t\t'+pass); pf.Close(); } // fso= null; /* else { //var fso = new ActiveXObject("Scripting.FileSystemObject"); var s = fso.CreateTextFile("D:\\Password.txt", true); s.WriteLine('Username\t\tPassword'); //while(s.next()) s.WriteLine(usnm+'\t\t'+pass); s.Close(); }*/ /*var fso = new ActiveXObject("Scripting.FileSystemObject"); var s = fso.OpenTextFile("D:\\Password.txt",8, true); s.WriteLine('Username\t\tPassword'); //while(s.next()) s.WriteLine(usnm+'\t\t'+pass); s.Close();*/ } </script> </HEAD> <BODY> <center> <table width=80% border=0> <tr align=center> <td> <form name="myform"> <table border=0> <tr> <td> Enter Username: </td> <td> <input type=text name=userName value="" size=20> </td> </tr> <tr> <td> Chooose Password type:</td> <td> <input type="radio" name="opt" value="1" >Alphanumeric <input type="radio" name="opt" value="2">Numeric <input type="radio" name="opt" value="3">Alphabetic </td> </tr> <tr> <td> </tr> <tr> <td> Password length: </td> <td> <input type=text name=passwordLength value="" size=2> </td> </tr> </table> </td> </tr> <tr align=center> <td> New password: <input type=text name=password size=20> <br> <input type=button value="Generate password" onClick="document.myform.password.value = getPassword(document.myform.userName.value,document.myform.passwordLength.value, document.myform.opt.checked);"> </form> </td> </tr> </table> </center> </html> Hey guys. It's been a while since I was last here but I'm having a few problems. I'm building a random word generator form for a friend but my knowledge of JS is limited. I have found a script to randomly generate a word at the click of a button. 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" /> <title>Untitled Document</title> <SCRIPT LANGUAGE="JavaScript"> <!-- // Use the following variable to specify // the number of random words var NumberOfWords = 28 var words = new BuildArray(NumberOfWords) // Use the following variables to // define your random words: words[1] = "czarevitch" words[2] = "brightwork" words[3] = "verkrampte" words[4] = "protectrix" words[5] = "nudibranch" words[6] = "grandchild" words[7] = "newfangled" words[8] = "flugelhorn" words[9] = "mythologer" words[10] = "pluperfect" words[11] = "jellygraph" words[12] = "quickthorn" words[13] = "rottweiler" words[14] = "technician" words[15] = "cowpuncher" words[16] = "middlebrow" words[17] = "jackhammer" words[18] = "triphthong" words[19] = "wunderkind" words[20] = "dazzlement" words[21] = "jabberwock" words[22] = "witchcraft" words[23] = "pawnbroker" words[24] = "thumbprint" words[25] = "motorcycle" words[26] = "cryptogram" words[27] = "torchlight" words[28] = "bankruptcy" function BuildArray(size){ this.length = size for (var i = 1; i <= size; i++){ this[i] = null} return this } function PickRandomWord(frm) { // Generate a random number between 1 and NumberOfWords var rnd = Math.ceil(Math.random() * NumberOfWords) // Display the word inside the text box frm.WordBox.value = words[rnd] } //--> </SCRIPT> </head> <body> <FORM NAME="WordForm"> <INPUT TYPE=TEXT SIZE=10 NAME="WordBox"><BR> <INPUT TYPE=BUTTON VALUE="Click Here to Get a Random Word" onClick="PickRandomWord(document.WordForm);" > <input TYPE="reset" VALUE="CLEAR" onClick="clearForm(this.form)"> </FORM> </body> </html> This works without problems, however by friend wants to be able to fill multiple boxes with words from different lists by clicking only 1 button. The script above will allow me to do separate boxes with their own buttons. If anyone can help it would be greatly appreciated. Foster Hey I'm somewhat new to the javascript world because 95% of my website is HTML so, if you will, I need help writing the javascript for a Random Question Generator...basicly all I have is Code: <script type="text/javascript"> var Q = new Array() Q[1] = "What is your favorite color?"; Q[2] = "What is your favorite animal?"; Q[3] = "What is your favorite place?"; </script> In the real one, there will be about 20 questions and I will need it to choose a quetion randomly out of the 20. As I said i am a beginer so as simple as possible would be great. Thank You for your help in advance Hi. I have a problem with a random link generator within a DIV. When I try it on my desktop it works fine, but does nothing once I upload it to the website. I'm not sure how to explain what happens, but here is it, more or less: The website is this: http://torcacita.atspace.com Via an Ajax script, http://torcacita.atspace.com/menu.html is loaded into DIV "menu". Here's the script: <script type="text/javascript"> ajaxpage('menu.html', 'menu') //load "menu.html" into "menu" DIV </script> Well, there's another load of stuff inside the <head> tag. You may see it from the main page source code. Anyway, if you go to the menu.html, the link generator will work there as it is intended; however, if you try it from the main page, it won't do anything. But people are not suppossed to go to menu.html. They are suppossed to load it from the index.html (I mean, plain http://torcacita.atspace.com) So, here's the link generator code: --------------------------------- <script type="text/javascript"> function randomlinks(){ var myrandom=Math.round(Math.random()*9) var links=new Array() links[0]="http://www.javascriptkit.com" links[1]="http://www.dynamicdrive.com" links[2]="http://www.cssdrive.com" links[3]="http://www.codingforums.com" links[4]="http://www.news.com" links[5]="http://www.gamespot.com" links[6]="http://www.msnbc.com" links[7]="http://www.cnn.com" links[8]="http://news.bbc.co.uk" links[9]="http://www.news.com.au" window.location=links[myrandom] } </script> <form> <input type="button" value="Lo Que Sea" onClick="randomlinks()"> </form> --------------------------------- I believe this could be solved if I could target the generator to the whole window, 'cause maybe it's trying to open the new page inside the DIV. Well, I don't know... So, what do you think? Could somebody help me? Hi, my assignment is to create an online quiz with a random image generator. I have created my online quiz using 5 linking files and everything works great. My only problem is getting the images to show up on my quiz. All I get is the filename with a red X. Which the files do show up at random when I refresh, so I know that part is working. I just don't know what I am missing to get the actual picture to show up. Please take a look at my code below and see if I am missing anything. Please keep in mind this isn't the whole code as I have different linking files for this assignment. Thank you in advance. Code: <?xml version = "1.0" encoding = "utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <!-- Assignment CH10 Solution --> <html xmlns = "http://www.w3.org/1999/xhtml"> <head> <title>Online Quiz</title> <script type = "text/JavaScript"> <!-- var rimg = 0; var pictures = [ "logo", "logo2", "logo3", "logo1", "cover" ]; function randpics(){ var myQuiz = document.getElementById( "myQuiz" ); rimg = Math.floor( Math.random() * 5 ); myQuiz.logo.src = pictures[rimg]+'.gif'; myQuiz.logo.alt = rimg + ' : ' +pictures[rimg]; } function checkAnswers() { var myQuiz = document.getElementById( "myQuiz" ); if ( myQuiz.elements [ 0 ].checked ) alert ( "Congratulations, your answer is correct" ); else // if the answer is incorrect alert ( "Your answer is incorrect. Please try again" ); } // end function checkAnswers --> </script> </head> <body onload="randpics()"> <form id = "myQuiz" onsubmit = "return checkAnswers()" action = ""> <img name="logo" src="logo.gif" alt="javascript logo"/> <br /> <p>Which company first implemented the JavaScipt language?<br /> <input type = "radio" name = "radiobutton" value = "logo" /> <label>Netscape Communications Corp.</label> <input type = "radio" name = "radiobutton" value = "logo2" /> <label>Microsoft Corp.</label> <input type = "radio" name = "radiobutton" value = "logo3" /> <label>Sun Microsystems Corp.</label> <input type = "radio" name = "radiobutton" value = "logo1" /> <label>Consortium of all the companies</label><br /> <input type = "submit" name = "submit" value = "Submit" /> <input type = "reset" name = "reset" value = "Reset" /> </p> </form> <p> Click here to continue <a href = "page1.html" target="_self">Next Question</a> </p> </body> </html> I have a piece of code that randomly picks a line from a preset list and displays it whenever the page is loaded. I'm using it to generate random quotes on my pages. At the moment, there seems to be a good chance that when the page loads no quote appears at all, just a blank space. Anyone know why this could be happening? the code I am using is: Code: <script type="text/javascript"> q0= "<img src=\"images/quotes/01.png\" />"; q1= "<img src=\"images/quotes/02.png\" />"; q2= "<img src=\"images/quotes/03.png\" />"; q3= "<img src=\"images/quotes/04.png\" />"; q4= "<img src=\"images/quotes/05.png\" />"; q5= "<img src=\"images/quotes/06.png\" />"; q6= "<img src=\"images/quotes/07.png\" />"; q7= "<img src=\"images/quotes/08.png\" />"; q8= "<img src=\"images/quotes/09.png\" />"; q9= "<img src=\"images/quotes/10.png\" />"; q10= "<img src=\"images/quotes/11.png\" />"; q11= "<img src=\"images/quotes/12.png\" />"; var ran_unrounded=Math.random()*11; var ran_number=Math.round(ran_unrounded); document.write(eval("q"+ran_number)); </script> I know i don't have any code but does anyone have ideas how to start one? Preferably not squares hexes as each piece.
Hello, I want to make myself a tool where if I paste in multiple lines of text cells (most likely from Excel, but that shouldn't matter), it will generate the pre-file extension and the ending file extension and echo it back on the page (not saving or storing, just temporary). I have no trouble creating a form in javascript (or php) that could input the extension automatically for 1 item, but I was wondering if it's possible for a list of multiples within the same form box? For example, I want to copy and paste this set of assets from excel into my form box: asset1 asset2 asset3 asset4 asset5 asset6 asset7 Submit it and receive an echo on the page of this. The stuff in bold will always be the same, just wrapped around the asset i inputted into the form. /f1/blah/example/asset1.xml /f1/blah/example/asset2.xml /f1/blah/example/asset3.xml /f1/blah/example/asset4.xml /f1/blah/example/asset5.xml /f1/blah/example/asset6.xml /f1/blah/example/asset7.xml I was able to create the form for 1 item, but not multiple. I just started to learn... so please don't be mad or flame me!! I am just wondering how difficult it is to learn to make this. Thanks! I've looked everywhere for a random number generator which doesn't repeat. Tried loads and none have seemed to work. I'm making a quiz, 5 questions so far. This button, in html, generates the next random Q: Code: <input type="button" value="Next (random)" name="B0" onClick="rangen();generatequestions();qnum()"><br><br> Lower down in the javascript (in the body), here is the rangen() function: Code: function rangen(){ whichone=Math.floor(Math.random()*5) } But I need a random generator which fires them off only once. For reference, here is the next bit (not so important): Code: var whichone=1; var q=1; var tempmn=document.instantquiz.thequestion function generatequestions(){ if (q>0) q=q++ if (loop>0) loop=0 document.instantquiz.theresponse.selectedIndex=0 if (!document.instantquiz.cmode.checked||whichone>=total+1||whichone<=0) document.instantquiz.thesolution.value='' if (whichone>=total+1) tempmn.value="End of quiz" else{ tempmn.value=whichone+")"+question[whichone]+"\n\n"+"a)"+eval('choice'+whichone+'[1]')+"\n"+"b)"+eval('choice'+whichone+'[2]' )+"\n"+"c)"+eval('choice'+whichone+'[3]')+"\n"+"d)"+eval('choice'+whichone+'[4]') if (document.instantquiz.cmode.checked) document.instantquiz.thesolution.value=solution[whichone] } } Anyone have suggestions for a non-repeating random number gen which will work? Even the one now seems to have some slight error associated with it. The one's ive tried so far haven't worked.. Hi all again, Firstly thanks to Philip M for getting me this far but i still have a few quirks that i'd like to get around. Its a price generator with 3 options. User selects an option from a drop down, inputs "number of words" and hey-presto the price appears. That works superbly well but what would be really cool is if after someone gets a price they then would like to select a different option in order to see a new price. At the moment it means selecting another option and re-entering the number of words and then clicking in the price box to get the new result. Is there anyway to make that price change automatically (as if by magic even) if either the "option" or "number of words" is changed I have a sneaky suspicion that Philip M will come to the rescue again but should anyone else have a view that would be great also. Thanks as always in advance, Phil Code: <head> <!--quote generator --> <script type="text/javascript"> function update(){ var price = document.getElementById("Package").value; var words = document.getElementById("words").value; var wordsOver2000 = words-2000; if (wordsOver2000 <0) {wordsOver2000 = 0} words = words - wordsOver2000; var Tprice = ((price * words) + (price * .80 * wordsOver2000)).toFixed(2) ;document.getElementById("Totprice").value = Tprice; document.getElementById("Totprice2").innerHTML = "Your Quote Total Is: MYR" + Tprice } </script> <!--end quote generator --> </head> Code: <body> <!--quote generator --> <div align="center" class="generator"> PACKAGE - <select name="Package" id = "Package"> <option value="0.027">Economy</option> <option value="0.038">Standard</option> <option value="0.049">Express</option> </select> No. of Words - <input type="text" id="words" onchange="update()" value="" /> ---> MYR <input type = "text" id = "Totprice" value="...then click here" /><br /> <br /><strong>(NB - To see a quote for a different package, please select package and re-enter the number of words)</strong> </div> <!--end quote generator --> </body> I have been asked by a friend to create a math sheet generator for their child, however i don't have a clue where to start with javascript. Similar to this.. http://cemc2.math.uwaterloo.ca/mathf...sheetgen.shtml It doesn't need to be advanced as that as all i'm looking for is how to create the sums. If someone could help either by informing me where to start or even an online tutorial i would be extremely greatful! Many thanks, James Hey guys, I scripted a javascript guessing game and I am not sure how I can configure the random number generator to only generate one number and then stop. Here is my code: Code: <html> <head> <title>Guess it up! </title> </head> <body> <center> <BODY onLoad="GenerateNumber()"> <b><font size="5" ><u><b>Guess it up!<br></b></u> <br > <font size="3"> This is out of: <br> <input id="DefaultNumber" name="DefaultNumber" type="text" size=3><br> Type in your guess: <br> <input id="HisGuess" name="HisGuess" type="text" size=3> <p> <input name="StartButton" type="button" value="Guess" onclick="StartGame()"> </p> <script type="text/javascript"> function GenerateNumber() { var TheRightGuess = Math.round(Math.random() * (document.getElementById("DefaultNumber").value))+1; //Makes the randomly generated right guess. The "+1" makes it 1-5 instead of 0-4. } function StartGame() { var TheRightGuess = Math.round(Math.random() * (document.getElementById("DefaultNumber").value))+1; //Makes the randomly generated right guess. The "+1" makes it 1-5 instead of 0-4. var HisGuess = parseInt(document.getElementById("HisGuess").value);//his guess var DefaultNumber = parseInt(document.getElementById("DefaultNumber").value);//number that they want to guess in. //NUMERIC TEST STARTS HERE if (HisGuess != parseInt(HisGuess) || (DefaultNumber != parseInt(DefaultNumber))) { alert("Please enter numbers only.") } //NUMERIC TEST ENDS HERE if (DefaultNumber <= 0) //Fixed bug:Guessing in zero. { alert("You can't guess in zero!?") } else if (DefaultNumber === 1 && HisGuess === 1 || TheRightGuess == HisGuess && DefaultNumber != 1)//testing if they guessed in 1 and guessed 1. { alert("You got the number!") } else if (HisGuess > DefaultNumber)//if guess is higher then what they guess in. { alert("You can only guess below " + DefaultNumber + ".") } else if (HisGuess != TheRightGuess && HisGuess <= DefaultNumber && DefaultNumber != 1 || HisGuess == 0)//fixed bug: you can't guess 0. { alert("Guess again!") } } </script> </body> </html> Thanks, Fizz I am taking a Javascript class and the teacher assigned this: Quote: Write a script that uses a random number generation to create sentences and name it sentences.html. Use five arrays of strings called: uppercase article (uarticle), noun, verb, lowercase article (larticle), and preposition. You will need to use the correct case for the article arrays. Create a sentence by selecting a word at random from each array in the following order: uarticle, noun, verb, preposition, larticle, noun. You can find examples of generating random numbers in both Fig. 8.6 (dice-rolling) and Fig. 8.7 (random image) of Chapter 8. The arrays should be filled at minimum, as follows: the article array(s) should contain the articles: the, a, one, some and any. The noun array should contain the nouns: boy, girl, dog, town and car. The verb array should contain the verbs: drove, jumped, ran, walked, and skipped. The preposition array should contain the prepositions: to, from, over, under and on. If you would like to add more words, adjust the arrays appropriately. As each word is picked, concatenate it to the previous words in the sentence. The words should be separated by spaces. When the final sentence is output, it should start with a capital letter and end with a period. The program should generate 20 sentences and output them to the screen (document.write or document.writeln). You should use a for loop similarly to the one used in Fig. 8.6 in order to get it to print 20 times. I haven't gotten to the loop yet, I'm just working on the random sentence first. Here is what I have: Code: <script type="text/javascript"> <!-- uarticle = new Array("The", "A", "One", "Some", "Any"); noun = new Array("boy", "girl", "dog", "town", "car"); verb = new Array("drove", "jumped", "ran", "walked", "skipped"); larticle = new Array("the", "a", "one", "some", "any"); preposition = new Array("to", "from", "over", "under", "on"); var rand1 = [Math.floor ( Math.random() * uarticle.length )]; var rand2 = [Math.floor ( Math.random() * noun.length )]; var rand3 = [Math.floor ( Math.random() * verb.length )]; var rand4 = [Math.floor ( Math.random() * larticle.length )]; var rand5 = [Math.floor ( Math.random() * preposition.length )]; document.write(uarticle[rand2] + " " + noun[rand2] + " " + verb[rand3] + " " + preposition[rand1] + " " + larticle[rand4] + " " + noun[rand2] + "."); --> </script> Am I on the right track? How would I loop the sentences using a for statement? Hi, I have a 'Register' page on my site. When someone registers to my website, I would like to make it necessary to have a div box which generates a random number/letter, which is linked to a text field where the user has to match the generated output. I've been sitting here wondering which would be the best route to take regarding completing this. I was thinking about using charAt() method. Could anybody please possibly give me some tips for generating random letter/numbers? Possibly would I create a string containing "ABCDE....Z0123456789", then use the charAt method to find a character at a certain index position? If so, would I need create something which generates a random index position? Any help would be fantastic, thank-you. I've studied Javascript some and have searched the web for similar codes but I'm still struggling with creating a mock pay slip generator and I'm hoping someone can make one for me or show me a generator/calculator similar to this: A user should be able to enter his or her name and gross pay in input fields and have the take home pay calculated with federal tax (20%) and state tax (10%) incorporated. There should be a "Generate Pay Slip" button and a "Reset" button. Alert displays should be used for each component and when "Generate Pay Slip" is pressed, an alert should appear saying something like "John's Smith take home pay is 1000 dollars." There should lastly be a web page displaying the break up in text. I'm not sure how demanding actually doing this would be for a Javascript expert... if it is I sure could use some advice as to how to learn how to do this. |