JavaScript - Creating A Generator Question
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! Similar TutorialsI'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. 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 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 Question about random link generator http://www.javascriptkit.com/script/cut1.shtml I want to use this script to hold a hundred odd links and show 8 random urls at a time in a list separated by a couple of line breaks. (Instead of just one). Could someone pls alter the code to allow me to do this please ... I also hope to keep the js file off the main html page. (naming the file list.js) Could someone also indicate how I do this. Hopefully these questions are easy if you know how etc. So far i havent been able to do it... Would be good if i could add a line to prevent duplicate randomly drawn links appearing in the list of eight.... thanks very much if you able to indicate it..... I have a table which has the number of rows depended on what the number is in the spinner. This does work e.g If I enter 25 in spinner it comes up with 25 rows, if I enter 7 in spinner comes with 7 rows. So my problem is this: What I have is a textarea where the user enters in their question and then submits the question, the question should be inserted and appear under the "Question" column. The problem is that everytime I submit a question into the table, it creates a new row. So if I had 20 empty rows in the table because I stated in the spinner I wanted 20 questions, then what happens is everytime I submit a question, it adds a new row every time, I want the question to be inserted in a current row starting from 1st row add going down 1 row every time a question is submitted. I have attached a document with this question which will show you how I want it to be displayed and what is displays currently and would hopefully explain it better for you if you are a bit confused. Code: Below is my javascript code: function insertQuestion() { var table = document.getElementById("qandatbl"); var tableBody = table.tBodies[0]; var textarea = document.getElementById("questionTxt"); var row = document.createElement("tr"); tableBody.appendChild(row); var enumeratorCell = document.createElement("td"); enumeratorCell.className = "qid"; row.appendChild(enumeratorCell); var questionCell = document.createElement("td"); questionCell.className = "question"; row.appendChild(questionCell); var weightCell = document.createElement("td"); weightCell.className = "weight"; row.appendChild(weightCell); var answerCell = document.createElement("td"); answerCell.className = "answer"; row.appendChild(answerCell); var questionText = textarea.value; var questionContent = document.createTextNode(questionText); questionCell.appendChild(questionContent); } Html code of table and text area with submit button: Code: // table where questions will be inserted into <table> <?php $spinnerCount = $_POST['textQuestion']; if($spinnerCount > 0) { for($i = 1; $i <= $spinnerCount; $i++) {?> // this get the number of questions from the spinner <tr> <td class="qid"><?php echo $i; ?></td> <td class="question"></td> <td class="weight"></td> <td class="answer"></td> </tr> </table> Code: //Text Area and submit button to submit questions <form id="enter" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post"> <table id='middleDetails' border='1'> <tr> <th class='tblheading' colspan='2'>SESSION DETAILS</th> </tr> <tr> <td id="questionNum">Question No </td> </tr> <tr> <td id="questionContent">Question:</td> <td id="questionTextarea"><textarea rows="5" cols="40" id="questionTxt" name="questionText"></textarea></td> </tr> <tr> <td id="addQuestionRow" colspan='2'><input id="addQuestion" type="button" value="Add Question" name="addQuestionBtn" onClick="insertQuestion()" /></td> </tr> </table> </form> Very new to javascript, so I apologize in advance. I honestly tried to figure this out on my own, and I'm just not able. I'm trying to create a family tree online that has several other related family charts. I want each person's name and birth year to be stored in javascript variables, then I want to be able to just go through the tree, and put the persons name once, and have it put the appropriate name and birthyear in the little boxes that the css is creating. In the js file... I would do this for each family member. Code: var johnname = "John Smith"; var johnbirthyear = "Jan 1 1930"; var janename = "Jane Doe"; var janebirthyear = "Jan 1 1940"; var mikename = "mike wilson"; var mikebirthyear = "Jan 1 1950"; var saraname = "sara johnston"; var sarabirthyear = "Jan 1 1960"; In the HTML file... Code: <div id = "boybox"> <script type="text/javascript"> id = "john"; <!-- this is the only thing I want to have to change --> name = id+"name"; document.write(name); </script> <div id = "year"> <script type="text/javascript"> birthyear = id+"year"; document.write(birthyear); </script> </div> </div> So I thought I had it all figured out. I thought that the above would take the id of John that I added, go to the line that sets the name, add john to the word name, and then document write the variable of johnname from the js file. I know you're laughing at me because of course it instead made the value of name to johnname, then wrote the word johnname in the box. Can anyone point me in the right direction please? ultimately I want to go through and be able to just type the persons name in the html for that box once, and have it update with their appropriate info. Thanks, and sorry for such a rookie question. Hi everyone, I was assigned to find out how to do this for my work. We were hoping for a javascript (but it could be PHP or other comparable format). Instead of the search function searching the website, we would like it to search a small database full of information. I have been reading for days now and have just gotten more confused. One thing I read (hopefully it was true) is that you can save a database as an HTML, then convert HTML to .JS which javascript will run. Any help would be greatly appreciated! Jeremy from Farmco Hey guys, basically Im creating a webpage for my univeristy degree, and I've decided to script a quiz, basically there will be several multi choice questions, and these will add to one answer, heres an example: Whats your favourite genre of music? (choice1) (choice2) (choice3) Whats your favourite favourite musical instrument? (choice1) (choice2) (choice3) etc answer = blahblahblah Heres my questions code here, as you can see im using values, im trying to create the answers by adding the values up, for example answer 1=5 2=10 3=100 <div id="quiz"> <h4> 1) What is your favourite genre of music?</div> <div class="qselections"> <input type="radio" value="1" name="question1">a)Rock<br> <input type="radio" value="2" name="question1">b) Punk<br> <input type="radio" value="3" name="question1">c) Metal<br> <input type="radio" value="4" name="question1">d)Electronica/Dance/Club<br> </div> <br> <div class="qheader"> 2) What is your favourite decade of music></div> <div class="qselections"> <input type="radio" value="1" name="question2">a) 60's<br> <input type="radio" value="2" name="question2">b) 70's<br> <input type="radio" value="3" name="question2">c) 80's<br> <input type="radio" value="4" name="question2">d) 90's<br> <input type="radio" value="5" name="question2">d) 00's<br> </div> <br> <div class="qheader"> 3) Which is your favourite instrument?</div> <div class="qselections"> <input type="radio" value="1" name="question3">a) Guitar<br> <input type="radio" value="2" name="question3">b) Drums<br> <input type="radio" value="3" name="question3">c) DJ Decks<br> <input type="radio" value="4" name="question3">d) Piano<br> </div> <br> <div class="qheader"> 4) Do you prefer handheld or console?</div> <div class="qselections"> <input type="radio" value="1" name="question4">a) Handheld<br> <input type="radio" value="100" name="question4">b) Console<br> <h4> </div> Im just curious how to script this? I havent done anything this difficult before, Im wondering how I would code this.. The only quiz I have done before is via prompts, any help will be much apprieciated! P.s feel free to ask any questions if it is to help! 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> 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 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. I know i don't have any code but does anyone have ideas how to start one? Preferably not squares hexes as each piece.
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> 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 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> 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. 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. Below is a function to download a set of images from a website based on the width, height and levels of the image which is obtained from the following config file: http://api.gigapan.org/beta/gigapans/10826.json If I use 10826 as the gigapanId, I get a width of 50944, height of 14269 and levels 9 for the below variables. What I am trying to do is rather then use this as a function, I want to convert this into a basic script which just outputs to the screen all the possible urls that images would be at based on the width, height and levels of the source gigapanId. Any thoughts on how I should do this? Should I be using javascript to do this or would another language be better for this? Thank you so much for any help! Chris Code: GigapanTileSource.prototype = new Seadragon.TileSource(); GigapanTileSource.prototype.constructor = GigapanTileSource; function GigapanTileSource(gigapanId, width, height) { Seadragon.TileSource.call(this, width, height, 256, 0, 8); this.gigapanId = gigapanId; //alert('gigapanid:'+gigapanId); this.getTileUrl = function(level, x, y) { if (level >= 8) { level = level - 8; } var url = 'http://share.gigapan.org/gigapans0/' + this.gigapanId + '/tiles'; var GC_TILE = ["0", "1", "2", "3"]; var name = "r"; var bit = 1 << level >> 1; while (bit) { name = name + GC_TILE[(x & bit ? (1) : (0)) + (y & bit ? (2) : (0))]; bit = bit >> 1; } var i = 0; while (i < name.length - 3) { url = url + ("/" + name.substr(i, 3)); i = i + 3; } if (gigapan[name] == null & gigapan[name] !== null) { //alert('no translation'); return (url + "/" + name + '.jpg'); }else{ //alert("gigapan['id']"+gigapan['id']+" gigapan["+name+"]:"+gigapan[name]); return ("http://farm4.static.flickr.com/" + gigapan[name] + ".jpg"); } }; Trying to develop a small app for my site. What is the code to generate a random # of lines (1 min - 5 max) and a random phrase for each line sourced from a multidimensional array? These also need to be unduplicated (so I won't have quote 1 be on lines 1 and 4). How do I prevent random duplication with the generated lines of text? Thanks!
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 |