Phoenix917 Posted September 23, 2007 Share Posted September 23, 2007 Yes, I am in school. The normal Javascript teacher has taken a sabbatical this year and I am stuck with an adjunct teacher who admittedly doesn't know Javascript. So, I have only the normal teacher's scarse PowerPoint slides and the internet to teach me Javascript. I am seriously asking myself why I bothered to pay for school if I had to teach myself anyway, but here I am... I am self-taught in html and a straight "A" student (which included intro Visual Basic). That being said (so I hopefully won't be railroaded...you guys seem very nice, though...), I have worked and worked over this code... I have read hundreds of pages at umpteen web sites (including tutorials)... There is no step-through Javascript like there is for Visual Basic. I can't find the problem in my code, but whatever it is, nothing works. There must be something I don't know about... Yet, I can't find what it could even be. Please, if have any assistance to offer, it would be greatly appreciated. Teaching yourself what you don't know is quite difficult, especially with Javascript. It seems it all works or nothing does. Thanks in advance... <!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=iso-8859-1" /> <title>Project 4 - Magic 8 Ball (Javascript)</title> <link href="project04stylesheet.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" language="javascript"> <!-- //Create function "resetAnswer" to reset the "Answer" marquee onKeyPress event of txtQuestion text box function resetAnswer() { Answer.innerHTML = "Ask the 8 Ball a question..."; } //Create function "Answerquestion" to come up with random answer and assign it to "Answer" marquee if it meets requirements when btnAsk is clicked function Answerquestion() { //Create the array "Message" var Message = new Array(); Message[0] = "Ask again later..."; Message[1] = "Yes!"; Message[2] = "Noooo..."; Message[3] = "It appears to be so!"; Message[4] = "The reply is hazy. Please try a new question."; Message[5] = "Definate affirmative!"; Message[6] = "What is it you really want to know?"; Message[7] = "The outlook is promising..."; Message[8] = "My sources say no."; Message[9] = "All of the signs point to yes."; Message[10] = "Don't count on it."; Message[11] = "I cannot predict this now."; Message[12] = "As I see it, yes."; Message[13] = "I better not tell you now..."; Message[14] = "Concentrate and ask your question in a different way..."; //Randomly pick a number between 0 and 14 and assign it to "count" //First line from the PowerPoints...Second line from the internet... //var count = Math.round(Math.random() * (13)) + 1; var count = Math.random()*response.length; count = Math.floor(count); //assign question asked to question variable var question = txtQuestion.value //Get last character of question asked var testLastChar = question.charAt(question.length - 1); //Create variables for the newQuestion and the oldQuestion var newQuestion = txtQuestion.value; var oldQuestion = question; //If "question" variable has nothing in it, alert user to enter a question. if(question == ""){ window.alert("Please enter a question."); txtQuestion.select(); //If the last character of the "question" variable isn't a "?", alert user to end their question with a "?" sign. Use "" or ''??? }else if(testLastChar != "?"){ window.alert("All questions MUST end with a "?". Everyone knows this! Quit wasting the 8 Ball's precious time and enter your question correctly, please!"); txtQuestion.select(); //Compare the newQuestion to the oldQuestion; if they match, give an error message. }else if(newQuestion == oldQuestion){ window.alert("Please ask a NEW question and quit wasting the 8 Ball's precious time!"); txtQuestion.select(); }else{ Answer.innerHTML = (Message[count]); } } //--> </script> </head> <body> <h1>Magic 8 Ball</h1> <br /> <h3>What would you like to know?</h3> <form id="form" name="form" method="post" action=""> <p> <input name="txtQuestion" type="text" class="txtQuestion" id="txtQuestion" accesskey="q" tabindex="1" size="60" onkeypress="resetAnswer()" /> </p> <p> </p> <p> <input name="btnAsk" type="button" class="btnAsk" id="btnAsk" accesskey="a" tabindex="2" value="Ask the 8 Ball" onClick="Answerquestion()" /> </p> <p> </p> <p> </p> <p>The 8 Ball says: </p> <marquee behavior="scroll" id="Answer">Ask the 8 Ball a question...</marquee> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
shawnyoung Posted September 24, 2007 Share Posted September 24, 2007 <!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=iso-8859-1" /> <title>Project 4 - Magic 8 Ball (Javascript)</title> <link href="project04stylesheet.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" language="javascript"> <!-- //Create function "resetAnswer" to reset the "Answer" marquee onKeyPress event of txtQuestion text box function resetAnswer() { Answer.innerHTML = "Ask the 8 Ball a question..."; } //Create function "Answerquestion" to come up with random answer and assign it to "Answer" marquee if it meets requirements when btnAsk is clicked var oldQuestion; function Answerquestion() { txtQuestion=document.getElementById("txtQuestion"); //Create the array "Message" var Message = new Array(); Message[0] = "Ask again later..."; Message[1] = "Yes!"; Message[2] = "Noooo..."; Message[3] = "It appears to be so!"; Message[4] = "The reply is hazy. Please try a new question."; Message[5] = "Definate affirmative!"; Message[6] = "What is it you really want to know?"; Message[7] = "The outlook is promising..."; Message[8] = "My sources say no."; Message[9] = "All of the signs point to yes."; Message[10] = "Don't count on it."; Message[11] = "I cannot predict this now."; Message[12] = "As I see it, yes."; Message[13] = "I better not tell you now..."; Message[14] = "Concentrate and ask your question in a different way..."; //Randomly pick a number between 0 and 14 and assign it to "count" //First line from the PowerPoints...Second line from the internet... //var count = Math.round(Math.random() * (13)) + 1; var count = Math.random()*Message.length; count = Math.floor(count); //assign question asked to question variable var question = txtQuestion.value //Get last character of question asked var testLastChar = question.charAt(question.length - 1); //Create variables for the newQuestion and the oldQuestion var newQuestion = txtQuestion.value; //If "question" variable has nothing in it, alert user to enter a question. if(question == ""){ window.alert("Please enter a question."); txtQuestion.select(); //If the last character of the "question" variable isn't a "?", alert user to end their question with a "?" sign. Use "" or '' }else if(testLastChar != "?"){ window.alert("All questions MUST end with a \"?\".Everyone knows this!\n Quit wasting the 8 Ball's precious time and enter your question correctly, please!"); txtQuestion.select(); //Compare the newQuestion to the oldQuestion; if they match, give an error message. }else if(newQuestion == oldQuestion){ window.alert("Please ask a NEW question and quit wasting the 8 Ball's precious time!"); txtQuestion.select(); }else{ Answer.innerHTML = (Message[count]); oldQuestion=newQuestion; } } //--> </script> </head> <body> <h1>Magic 8 Ball</h1> <h3>What would you like to know?</h3> <form id="form" name="form" method="post" action=""> <p> <input name="txtQuestion" type="text" class="txtQuestion" id="txtQuestion" accesskey="q" tabindex="1" size="60" onkeypress="resetAnswer()" /> </p> <p> </p> <p> <input name="btnAsk" type="button" class="btnAsk" id="btnAsk" accesskey="a" tabindex="2" value="Ask the 8 Ball" onClick="Answerquestion()" /> </p> <p> </p> <p> </p> <p>The 8 Ball says: </p> <marquee behavior="scroll" id="Answer">Ask the 8 Ball a question...</marquee> </form> </body> </html> a lot simpler! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.