JavaScript - Help With School Assignment
Similar TutorialsI have to create a function that uses infoMenu(), and I am having a hard time with this. I have created a loadInfo() function, and I am supposed to follow the same steps, but for some reason I am not getting it. Below is an example of what I have done already. Code: function loadInfo(myForm) { var menuSelect=myForm.Menu.selectedIndex var menuUrl=myForm.Menu.options[menuSelect].value+".html" window.location=menuUrl } This is what I placed in my select tag to in order to go to the pages once they were selected. Code: <select name="Menu" onchange="loadInfo(this.form)"> What i am trying to do is create the infoMenu() function that uses the selectedIndex value of the moreInfo <select> list in the menuInfo<form>. Any help would be greatly appreciated This post is going to seem long because of the coding in it, but the solutions I need are simple. BASICALLY I need to know: 1) where to use the if's and else's 2)how to call the boolean method isEmpty() from the CanOfCoke class 3)how to apply methods from the other classes to the machine, bin, and can variables 4) how to check to see if an ArrayList has any content (ie if the student has any coins or not) This is complicated for me to complain because I'm a complete n00b and this is my first Java class, but I hope someone can help me because my teacher isn't all that great at explaining things. and I'm stuck on the LAST method of the LAST class of our FINAL project lol. The project has 5 classes: Coin DrinksMachine CanOfCoke GarbageDisposalUnit Student I am working on the Student class and here is the code I have so far: Code: import java.util.ArrayList; /** * Write a description of class Student here. * * @author xxx * @version Project part 5 */ public class Student { private String name; private ArrayList purse; private boolean sobbing; private DrinksMachine machine; private GarbageDisposalUnit bin; private CanOfCoke can; /** * Constructor for objects of class Student * * @ param pName The name of the studen * @ param nCoins The number of coins the student has */ public Student(String pName, int nCoins) { name = pName; purse = new ArrayList<Coin>(nCoins); sobbing = false; machine = null; bin = null; can = null; } /** * This method will set the students machine variable * * @param name of the machine */ public void setMachine(DrinksMachine aMachine) { machine = aMachine; } /** * This method will set the students garbage disposal unit * * @param name of the garbage disposal unit */ public void setBin(GarbageDisposalUnit aBin) { bin = aBin; } /** * This method will print out information about the student * */ public void displaySelf() { if (can == null) { System.out.println(name + " does not have a can of Coke."); } else { System.out.println(name + " has a can of Coke."); } if (sobbing == true) { System.out.println(name + " is sobbing."); } else { System.out.println(name + " is not sobbing."); } System.out.println(name + " has" + purse.size() + " coins in their purse."); } /** * This method will perform the actions of: * * If they have a can of coke: * The student takes a single sip from a can of Coke and puts it in the trash bin when empty. * * If they don't have a can of coke: * The student inserts a coin and obtain the can of coke and take a sip from it. * * If they can't get a can of coke: * The student sobs. * */ public void doAction() { if (can != null) { can.giveSip(); } else if (can.isEmpty()) { bin.addCan(bi); can = null; } else { if (purse != null && can != isEmpty()) { machine.insertCoin(); machine.deliverCan(); can.open(); can.giveSip(); } else { sobbing = true; } } } } This is the part I am having troubles with: [CODE public void doAction() { if (can != null) { can.giveSip(); } else if (can.isEmpty()) { bin.addCan(bi); can = null; } else { if (purse != null && can != isEmpty()) { machine.insertCoin(); machine.deliverCan(); can.open(); can.giveSip(); } else { sobbing = true; } } } } [/CODE] Here are his horrible instructions: a method with signature public void doAction() which performs the following actions: i. if the Student has a can of Coke then they take a single sip from it. If it becomes empty they put it in the bin, and cease to hold it (i.e. can is set to null). The doAction() method then exits. ii. if the Student does not have a can of coke then they insert a Coin(if they have one) into the coke machine (if it isn't empty), take the can of Coke they have paid for, and take a sip from it (after opening the can). If for any reason they are unable to get a can of Coke (machine empty, or no Coins) they begin to sob. iii. Pseudo-code for this is shown below: IF the student has a can THEN take a sip IF the can is now empty THEN add it to the bin OTHERWISE (i.e. the student does not have a can to start with) IF the student has a Coin AND the machine is not empty THEN insert a Coin into the machine reduce Coins by one get the can from the machine open the can and take a sip OTHERWISE student starts sobbing Hello there, I'm a 30yr old returning to school and I signed up for a CMIS102 class, thinking it be more explanatory as the syllabus let on. But I was wrong. While I do understand some of what the professor has been teaching us, like modular programming and IfElse statements, I can't wrap my head around things like While Loops. My professor has saddled us with a couple assignments, requiring us to write in pseudocode and I was wondering if anyone could explain what he wants from this assignment or even help me with it, that maybe I can finally have a grasp of it, and will know what I'm doing on the final. ~Tia P.S. I've posted the assignment question below: I need to write a pseudo-codepseudocode for the following question but don't know how: Write a program to read a list of exam scores (in the range 0 to 100) and to output the total number of grades and the number of grades in each letter=grade category. The end input is indicated by a negative score as a sentinel value. (The negative value is used only to end the loop, so do not use it in the calculations. Example: 88 93 55 77 100 -1 (The output would be) Total number of grades = 5 Number of A's =2 Number of B's = 1 Number of C's =1 Number of D's = 0 Number of F's =1 Must prompt user to run again Hi, I would like to create a calculator which can help parents when they calculate their student's school fees on our school's joomla web site. Ive attached our school's fee table. Is there anyone who can help me please? Regards I have a class assignment that involves finding a simple recipe, and creating a unit conversion using JavaScript that tells me the exact unit of each item required to make x amount of servings. I have this so far, and every time I try to convert the units, the new units are the exact same as the original units. Please help! Code: <HTML> <HEAD> <TITLE>COMSC-100-1241 - Assignment #7 - Your Own Recipe Conversion Program</TITLE> <SCRIPT LANGUAGE="JavaScript"> function Convert(){ // Assign Variables servingsBase = parseFloat(document.getElementById("servingsBase").value); servingsNeeded = parseFloat(document.getElementById("servingsNeeded").value); var amount1 = parseFloat(document.getElementById("item1").value); document.getElementById("amount1").value = amount1 / servingsBase * servingsNeeded; var amount2 = parseFloat(document.getElementById("item2").value); document.getElementById("amount2").value = amount2 / servingsBase * servingsNeeded; var amount3 = parseFloat(document.getElementById("item3").value); document.getElementById("amount3").value = amount3 / servingsBase * servingsNeeded; } </SCRIPT> </HEAD> <BODY> <TABLE BORDER="1" WIDTH="700" ALIGN="center"> <TR> <TD> <DIV ALIGN="left"> <DIV ALIGN="center"> <B>BRIE BRUSCHETTA</B> <BR> <B>Recipe Website:</B> <A HREF="http://busycooks.about.com/od/appetizerrecipe1/r/briebruschetta.htm" TARGET="_blank">http://busycooks.about.com/od/appetizerrecipe1/r/briebruschetta.htm</A> </DIV> <BR> <B>Directions: </B> <OL> <LI>Under broiler or on grill, toast one side of the french bread slices. <LI>Turn slices over. <LI>Brush the untoasted side with some of the juices that result when you chop the tomatoes. <LI>Layer slices of brie on the bread. <LI>Return to broiler or grill and toast 2-3 minutes, until cheese is melted. <LI>Top with the chopped cold tomatoes and sprinkle with salt and pepper. Serve immediately! </OL> <BR> <B>Ingredients: </B> <UL> <LI>12 Slices of French Bread <LI>6 Ripe Tomatoes (chopped) <LI>8 Ounces of Brie Cheese (thinly sliced) </UL> <B>Prep Time: </B> 15 minutes <BR> <B>Cook Time: </B> 5 minutes <BR> <B>Total Time: </B> 20 minutes <BR> <B>Yield: </B> 4 servings </DIV> </TD> </TR> </TABLE> <BR> <TABLE BORDER="0" WIDTH="550" ALIGN="center"> <TR COLSPAN="4"> <DIV ALIGN="center"> <B><U>Recipe Converter</U></B> </DIV> </TR> <TR> <TD WIDTH="300"> <B>First Ingredient & Unit</B> </TD> <TD WIDTH="100"> <INPUT TYPE="text" ID="item1" VALUE="French Bread, slices"> </TD> <TD WIDTH="50"> <B>Amount: </B> </TD> <TD WIDTH="100"> <INPUT TYPE="text" ID="amount1"> </TD> </TR> <TR> <TD WIDTH="300"> <B>Second Ingredient & Unit</B> </TD> <TD WIDTH="100"> <INPUT TYPE="text" ID="item2" NAME="item2" VALUE="Tomatoes, each"> </TD> <TD WIDTH="50"> <B>Amount: </B> </TD> <TD WIDTH="100"> <INPUT TYPE="text" ID="amount2"> </TD> </TR> <TR> <TD WIDTH="300"> <B>Third Ingredient & Unit</B> </TD> <TD WIDTH="100"> <INPUT TYPE="text" ID="item3" NAME="item3" VALUE="Brie Cheese, ounces"> </TD> <TD WIDTH="50"> <B>Amount: </B> </TD> <TD WIDTH="100"> <INPUT TYPE="text" ID="amount3"> </TD> </TR> <TR> <TD COLSPAN="2"> <B>Recipe Makes This Many Servings: </B> </TD> <TD COLSPAN="2"> <INPUT TYPE="text" ID="servingsBase" NAME="servingsBase"> </TD> </TR> <TR> <TD COLSPAN="2"> <B>I Want To Make This Many Servings: </B> </TD> <TD COLSPAN="2"> <INPUT TYPE="text" ID="servingsNeeded" NAME="servingsNeeded"> </TD> </TR> <TR> <TD COLSPAN="4"> <DIV ALIGN="center"> <INPUT TYPE="Button" VALUE="Convert" OnClick="javascript:Convert();"> </DIV> </TD> </TR> </TABLE> </BODY> </HTML> Hello, in semester 2 of my first year of a Business Computer Systems. Anyway for my recent assignment I need to build a pretty basic shopping cart and have some cilent side validation as well. ----------------------------------------- Shopping Cart Anyway for the shopping cart do i have to: Item = goes into its own array Amount = goes into its own array price = goes into its own array then use a retrieve function to add each array into different sections in a table. and then simply times the amounts by their prices then add them all together using for loops? or can Item Amount = All in the same array. Price Then use a for loop to detect the correct data from the array for each section of the shopping cart? ----------------------------------------- Client Side Validation Presumably I just use simply javascript to detect phone numbers within a box form. i.e. (in simply english) if amount in phone form is < 11 then display alert. same for @ and . for email address? Hi, I have been working on a CS assignment that pertains to calculating the total cost (including tax) once a certain item is bought (there are a total of 4 different products). I can't get the code to work, so any help is much appreciated. Thank you. Question: Create a Web page that contains 1 text field and 1 button. The text field will be used to display the product/service ordered. Use a prompt window to get the user's name. Convert their name to proper case. Use an alert window to display a welcome message that includes their name. Use a prompt window to ask the user which one of four products/services they wish to purchase. Based on their input, calculate the tax and total cost for this product/service. Display the product/service ordered in the proper field. Then create bill. At the end, use the an alert window to display a message telling the user to click the browser's Back button to reload the page to start again. Code so far: Code: <html> <head> <title> Android World Products </title> <script type="text/javascript"> <!-- var fullName = ""; function askName() { fullName = prompt("Please Enter Your Name:"); var x = fullName.indexOf(" "); var firstName = fullName.substring(0,x); firstName = firstName.substring(0,1).toUpperCase() + firstName.substring(1); var lastName = fullName.substring(x+1); lastName = lastName.substring(0,1).toUpperCase() + lastName.substring(1); fullName = firstName + " " + lastName; if (x > -1) alert("Welcome " + fullName); else alert("Please try again."); } var evoPrice = 250.00; var optimusPrice = 200.00; var captivPrice = 150.00; var casePrice = 30.00; var products = new Array('HTC Evo 4G','LG Optimus S','Samsung Captivate','Leather Case'); var prices = new Array(evoPrice,optimusPrice,captivPrice,casePrice); var tax = 1.08375; var totalCost = 0; if(product==1) {totalCost = evoPrice + (evoPrice*tax); } else if(product==2) {totalCost = optimusPrice + (optimusPrice*tax); } else if(product==3) {totalCost = captivPrice + (captivPrice*tax); } else if(product==4) {totalCost = casePrice + (casePrice*tax); } return totalCost; } var seeBill = confirm("Click OK to See Your Bill"); if(seeBill) { Window = window.open("","Receipt","width=200,height=200"); Window.document.write("Android World <br>"); Window.document.write("Customer Name: "+Name+"<br>"); if(product=="1") {Window.document.write("Product: "HTC Evo 4G"<br>"); Window.document.write("Cost: $"evoPrice"<br>"); } else if(product=="2") {Window.document.write("Product: "LG Optimus S"<br>"); Window.document.write("Cost: $"optimusPrice"<br>"); } else if(product=="3") {Window.document.write("Product: "Samsung Captivate"<br>"); Window.document.write("Cost: $"captivPrice"<br>"); } else if(product=="4") {Window.document.write("Product: "Leather Case"<br>"); Window.document.write("Cost: $"casePrice"<br>"); } Window.document.write("Tax: 8.375%<br>"); Window.document.write("Your total cost for this purchase: $"totalCost"<br>"); Window.document.write("Thank you for shopping at Android World!"); function show_prompt() <input type=button value="Try it now" onClick="alert('Please use the browser's back button to reload the page')"> </script> </head> <body onload="askName ()"> <body style="background-color:#66FF66"> <h1> Android World Products </h1> <ol>Offered Products: <li>HTC Evo 4G: $250.00</li> <li>LG Optimus S: $200.00</li> <li>Samsung Captivate: $150.00</li> <li>Leather Case: $30.00</li> </ol> <br> <!--form name="Form" action="" method=""> <br> <input type="text" name="customer" onclick="typename()" /> <input type="button" name="" value="Confirm Your Purchase" onclick="" /> </form> </body> </html> First of all, Who's the best Javascript here?
http://i50.tinypic.com/2njcxn5.png basically.. a button that changes the color of that box.. the font to bold.. and changes a frame from two search engine websites. Here is the assignment: Ocean Levels Assuming the ocean’s level is currently rising at about 1.5 millimeters per year, write a program that displays a table showing the number of millimeters that the ocean will have risen each year for the next 25 years. (we should use a "for" loop) Here is my code so far: <html> <head> <title>Ocean Page</title> <script type = "text/javascript"> var year, rise; document.write("Number of Years Ocean Level <br />"); year_str = alert("This will give you the prediction of ocean level rise for up to 25 years", ""); year_str= 25 year = parseFloat(year_str); rise_str = alert("The Ocean Rises at 1.5 milimeters a day", ""); rise_str = 1.5 rise_str = parseFloat(rise_str); r= parseFloat(rise_str) var MAX_VALUE = r; for (rise=1; rise <= r; ++rise ) { distance = rise * year document.write(year+" years   "+ distance+" ocean level <br />"); } </script> </head> <body> <h3>Click Refresh (or Reload) to run the script again</h3> <br /> </body> </html> END So far it just gives me years 25 ocean level 25. I can probably figure out how to create a table...but I'm having an issue getting the 1.5 to multiply 25 times. Any help? I'm a newby =) Thanks a million!!!!!!!!!!!! =) Hey thanks in advance to anyone who can take a peak at my code and hopefully point me in the correct direction. I have been working on my final project in my javascript class for a bit, and there are a few erros I cant seem to find through firebug or error console. It is due this evening at midnight, so anyone that could help, I really need this assignment for a decent grade. Basically there are two issues so far, one needs to be solved so the other can be as well. First, line 103 - 105 should create a hyperlink to the specified id, but is doesn't return a number. so the link goes no where it is this code: PHP Code: //create hypertext link to the section heading var linkItem = document.createElement("a"); linkItem.innerHTML = n.innerHTML; linkItem.href = "#" + n.id; Next I belive there is a problem with the function expandCollapseDoc(), that might fix itself when the other problem is solved. The document should expand and collapse with the menu. Here is my javascript code: PHP Code: /* New Perspectives on JavaScript, 2nd Edition Tutorial 7 Tutorial Case Author: Mike Cleghorn Date: 2-15-10 Filename: toc.js Global Variables: sections An array contain the HTML elements used as section headings in the historic document Functions List: addEvent(object, evName, fnName, cap) Adds an event hander to object where evName is the name of the event, fnName is the function assigned to the event, and cap indicates whether event handler occurs during the capture phase (true) or bubbling phase (false) makeTOC() Generate a table of contents as a nested list for the contents of the "doc" element within the current Web page. Store the nested list in the "toc" element. levelNum(node) Returns the level number of the object node. If the object node does not represent a section heading, the function returns the value -1. createList() Goes through the child nodes of the "doc" element searching for section headings. When it finds a section heading, a new entry is added to the table of contents expandCollapse() Expands and collapse the content of the table of contents and the historic document expandCollapseDoc() Goes through the child nodes of the "doc" element determining which elements to hide and which elements to display isHidden(object) Returns a Boolean value indicating whether object is hidden (true) or not hidden (false) on the Web page by examining the display style for object and all its parent nodes up to the body element */ function addEvent(object, evName, fnName, cap) { if (object.attachEvent) object.attachEvent("on" + evName, fnName); else if (object.addEventListener) object.addEventListener(evName, fnName, cap); } addEvent(window, "load", makeTOC, false); var sections = new Array("h1","h2","h3","h4","h5","h6"); var sourceDoc; //document on which TOC is based on function makeTOC(){ var TOC = document.getElementById("toc"); TOC.innerHTML = "<h1>Table of Contents</h1>"; var TOCList = document.createElement("ol"); TOC.appendChild(TOCList); sourceDoc = document.getElementById("doc"); //generate list items containing section headings createList(sourceDoc, TOCList); } function levelNum(node) { for (var i = 0; i < sections.length; i++) { if(node.nodeName == sections[i].toUpperCase()) return i; } return -1; //node is not section heading } function createList(object, list) { var prevLevel = 0; //level of the pervious TOC entry var headNum = 0; //running count of headings for (var n = object.firstChild; n != null; n = n.nextSibling) { //loop through all nodes in object var nodeLevel = levelNum(n); if (nodeLevel != -1) { //node represents a section heading //insert id for the section heading if necessary headNum++; //create list item to match var listItem = document.createElement("li"); listItem.id = "TOC" + n.id; //create hypertext link to the section heading var linkItem = document.createElement("a"); linkItem.innerHTML = n.innerHTML; linkItem.href = "#" + n.id; //append the hypertext to the list entry listItem.appendChild(linkItem); if (nodeLevel == prevLevel) { //append the entry to the current list list.appendChild(listItem); } else if (nodeLevel > prevLevel) { //append entry to new nest list var nestedList = document.createElement("ol"); nestedList.appendChild(listItem); list.lastChild.appendChild(nestedList); //add plus/minus box beffore the text var plusMinusBox = document.createElement("span"); plusMinusBox.innerHTML = "--"; addEvent(plusMinusBox, "click", expandCollapse, false) nestedList.parentNode.insertBefore(plusMinusBox, nestedList.previousSibling); list = nestedList; prevLevel = nodeLevel; } else if (nodeLevel < prevLevel) { //append entry to a higher-level list var levelUp = prevLevel - nodeLevel; for (var i = 1; i<= levelUp; i++) {list = list.parentNode.parentNode;} list.appendChild(listItem); prevLevel = nodeLevel; } } } } function expandCollapse(e) { var plusMinusBox = e.target || event.srcElement; var nestedList = plusMinusBox.nextSibling.nextSibling; //Toggle the plus and minus symbol if (plusMinusBox.innerHTML == "--") plusMinusBox.innerHTML = "+" else plusMinusBox.innerHTML = "--"; //Toggle display of nested list if(nestedList.style.display == "none") nestedList.style.display = "" else nestedList.style.display = "none"; //expand/collapse doc to match TOC expandCollapseDoc(); } function expandCollapseDoc() { var displayStatus = ""; for (var n = sourceDoc.firstChild; n != null; n = n.nextSibling) { var nodeLevel = levelNum(n); if (nodeLevel != -1) { //determain display status of TOC entry var TOCentry = document.getElementById("TOC" + n.id); if (isHidden(TOCentry)) displayStatus = "none" else displayStatus = ""; } if (n.nodeType == 1) { //apply to current status for the node n.style.display = displayStatus; } } } function isHidden(object) { for (var n = object; n.nodeName != "BODY"; n = n.parentNode) { if (n.style.display = "none") return true; } return false; } the html was too long, so i uploaded it to my webspace you can check out the almost working version at http://www.kinetic-designs.net/final/usconst.htm Again thank you so much! Any questions just ask! Hey there, so this is my first time using this website. I was wondering if anyone can help me resolve this problem. It is for my Website Development Class and I am going use this forum to help me understand the languages haha. But Anyways. My homework assignment I have to do is: Create a Web page named gpa.html that can be used to compute your grade point average given grades and hours for courses completed. The page should repeatedly prompt the user for course information, reading the course name, grade received, and credit hours for a particular course in a single dialog box. While the user is done inputting the information, it should display on the website like this: COURSE GRADE HOURS THL100 B+ 3 PHL107 A 3 ENG120 C+ 3 MTH245 A 4 CSC221 A 3 Total grade points = 58 Number of hours = 16 GPA = 3.625 So my problem is that when I tried to display it outside the while loop it only displays "NaN". Please Help and Thanks! Here is my code: <!DOCTYPE html> <html> <!-- gpa.html--> <head> </head> <body> <script type= "text/javascript"> document.write("Course - Grade - Credit Hours"); document.write("<br>"); var third; var total = 0; var total2 = 0; var total4 = 0; var t_hrs = 0; var user; while (user != "") { user = prompt("Hello User. Enter course name, grade, & credit hours (i.e CS3240 B+ 3), or click OK with no data to terminate."); var uInput = user.split(" "); document.write(uInput); document.write("<br>"); third = uInput[2]; t_hrs = parseInt(t_hrs) + parseInt(uInput[2]); if (uInput[1] == "A"){ letter2point = 4.0; } else if (uInput[1] == "B+"){ letter2point = 3.5; } else if (uInput[1] == "B"){ letter2point = 3.0;} else if (uInput[1] == "C+"){ letter2point = 2.5; } else if (uInput[1] == "C"){ letter2point = 2.0; } else if (uInput[1] == "D"){ letter2point = 1.0; } else if (uInput[1] == "F"){ letter2point = 0.0; } total = letter2point * third; total2 = total2 + total; total4 = total2 / t_hrs; } document.write(total4) </script> </body> </html> Reply With Quote 01-29-2015, 02:47 AM #2 felgall View Profile View Forum Posts Visit Homepage Master Coder Join Date Sep 2005 Location Sydney, Australia Posts 6,745 Thanks 0 Thanked 666 Times in 655 Posts If that antiquated JavaScript is what your course is teaching then I feel sorry for you. Just about every statement that you have there is listed on one of the "Bad Bits" pages of my Introducing JavaScript web site where it gives the reasons for not using those 20 year old code constructs in modern web browsers (which means IE5 and any browser more recent than that). A couple of suggestions to get you started. 1. The second document.write is not complete so everything from there onward is broken. 2. To convert to a number use Number((t_hrs) or (+t_hrs). If you must use parseint then always include the second parameter to specify the number base you are converting from parseInt(t_hrs, 10) - with regard to t_hrs it is a number to start with so doesn't even need this conversion. 3. Use === and !== instead of == and != as the two character versions don't always give the expected result where the three character versions always do. Hello everybody, could anyone offer an insight into why this isn't work please? It should be a simple project I was given at college but it stops near the end. The task is to ask a user for a word using a form, then spell it out backwards — stupid, but, hey — it's a lesson! Here's the code: Thanks. <h2>JavaScript exercise 4</h2> <p>Ask the user for a string of text. This must then be displayed in reverse. (For example, if the user enters the words "Hello World!" an alert dialog box should appear with "!dlroW olleH") </p> <form action="javascript: displaymessage();" method="get"> <p>Please enter a word: <input id="user_word" name="user_wrd" type="text"> <input type="submit" value="Submit"> </p> </form> <script> function displaymessage() { /*Set a variable for the user's word*/ var word_forward; /*Get the user's word from the from above and put it into the variable*/ word_forward = document.getElementById("user_word").value; /*Write the user's word from the variable to the page*/ document.write("<p>The word is: " + word_forward + ".</p>"); /*Calculate the length of the user's word*/ var word_length=word_forward.length; /*Write the length of the user's word to the page*/ document.write("<p>The word length is: " + word_length + " characters.</p>"); /*Subtract 1 from word length to allow for character index numbers starting from zero*/ word_length2=(word_length-1); /*Set a variable for the character index number*/ var char_num; /*Begin character index number countdown loop: loop start value / loop end value / increment*/ for(char_num=word_length2; char_num=0; char_num--) { /*Write word backwards using charAt*/ document.write("The word spelled backwards is: " + word_forward.charAt(char_num)); } } </script> OK Once again not out to spam . I am confused on this assignment? this is what i need to do The Sieve of Eratosthenes An integer is a prime number if it is evenly divisible by only itself and 1. There are several ways to find all prime numbers within a given range of integers, and the Sieve of Eratosthenes is an algorithm for to do just that. It operates as follows: Create an array with all elements initialized to 1 (true). Array elements with prime subscripts will remain as 1. All other array elements will eventually be set to zero. Starting with array subscript 2 (subscript 1 must be prime), every time an array element is found whose value is 1, loop through the remainder of the array and set to zero every element whose subscript is a multiple of the subscript for the element with value 1. For array subscript 2, all elements beyond 2 in the array that are multiples of 2 will be set to zero (subscripts 4, 6, 8, 10, etc.); for array subscript 3, all elements beyond 3 in the array that are multiples of 3 will be set to zero (subscripts 6, 9, 12, 15, etc.); and so on. When this process is complete, the array elements that are still set to 1 indicate that the subscript is a prime number. These subscripts can then be printed. Write a script that uses an array of 1000 elements to determine and print the prime numbers between 1 and 999. Ignore element 0 of the array. Ok for anyone who may understand, what am i supposed to create as output? Am i supposed to get a one big chart of numbers? or do i get a forever flow of numbers? suggestions please I am not really looking for code, just want some idea of what am i supposed to make as output? thanks Hi All, This is my function function outputSelected() { alert(window.opener.document.forms[0].txt11_19.value); alert(window.opener.document.forms[0].rdo11.length); var questionID = document.forms[0].cntQuestion.value; var choiceID = document.forms[0].cntChoice.value; var txtValue = document.forms[0].strEmpNo.value + " " + document.forms[0].strName.value; alert(txtValue); var leftValue = 'window.opener.document.forms[0].txt' + questionID + '_' + choiceID + '.value =' + txtValue; eval(leftValue); } all the alerts work as expected. bu the eval function does not. error: expected ';' any ideas what is happening. or is there any other way of doing this. Hey, I'm taking a javascript class and have to do an assignment in which I'm supposed to show countdowns to various events. I have 2 files, an external js file and a html file. But I can't get it to work I've searched the forum and googled it but all the solutions I've found do not work. Here's the code. .js file: Code: /* New Perspectives on JavaScript, 2nd Edition Tutorial 2 Review Assignment Author: Date: Function List: showDateTime(time) Returns the date in a text string formatted as: mm/dd/yyyy at hh:mm:ss am changeYear(today, holiday) Changes the year value of the holiday object to point to the next year if it has already occurred in the present year countdown(stop, start) Displays the time between the stop and start date objects in the text format: dd days, hh hrs, mm mins, ss secs */ function showDateTime(time) { var date = time.getDate(); var month = time.getMonth()+1; var year = time.getFullYear(); var second = time.getSeconds(); var minute = time.getMinutes(); var hour = time.getHours(); ampm = (hour < 12) ? " a.m." : " p.m."; hour = (hour > 12) ? hour - 12 : hour; hour = (hour == 0) ? 12 : hour; minute = minute < 10 ? "0"+minute : minute; second = second < 10 ? "0"+second : second; return month+"/"+date +"/"+year+" at "+hour+":"+minute+":"+second+ampm; } function changeYear (today, holiday) { var year = changeYear.getFullYear(); holiday.setFullYear(year); year = (today > holiday) ? year + 1 : year; year = holiday.setFullYear(year); } function countdown(start, stop) { time = stop - start; seconds = Math.floor(time/1000); minutes = Math.floor(seconds/60); hours = Math.floor(minutes/60); days = Math.floor(hours/24); return days + " days," + hours + " hours," + minutes + " mins," + seconds + " secs"; } And here's the HTML file: Code: <?xml version="1.0" encoding="UTF-8" ?> <!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> <!-- New Perspectives on JavaScript, 2nd Edition Tutorial 2 Review Assignment Events in Tulsa Author: Date: Filename: events.htm Supporting files: dates.js, logo.jpg, tulsa.css --> <title>Upcoming Events at Tulsa</title> <link href="tulsa.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="dates.js"></script> <script type="text/javascript"> showCountdown(){ var today = new Date("October 31, 2010 10:00:00"); var Date1 = new Date("January 14, 2011 10:00:00"); var Date2 = new Date("May 21, 2011 12:00:00"); var Date3 = new Date("July 4, 2011 9:00:00"); var Date4 = new Date("September 1, 2011 12:00:00"); var Date5 = new Date("December 1, 2011 11:30:00"); var Date6 = new Date("December 31, 2011 3:30:00"); document.eventform.thisDay.value = showDateTime(today); changeYear(today, Date1); changeYear(today, Date2); changeYear(today, Date3); changeYear(today, Date4); changeYear(today, Date5); changeYear(today, Date6); document.eventform.count1.value = countdown(today, Date1); document.eventform.count2.value = countdown(today, Date2); document.eventform.count3.value = countdown(today, Date3); document.eventform.count4.value = countdown(today, Date4); document.eventform.count5.value = countdown(today, Date5); document.eventform.count6.value = countdown(today, Date6); } </script> </head> <body onload="setInterval('showCountdown()', 100)"> <form name="eventform" id="eventform" action=""> <div id="logo"> <img src="logo.jpg" alt="Tulsa Events" /> </div> <div id="links"> <a href="#">Home</a> <a href="#">City Services</a> <a href="#">City Agencies</a> <a href="#">Mayor's Office</a> <a href="#">News Today</a> <a href="#">Upcoming Events</a> <a href="#">Site Map</a> <a href="#">Search Engine</a> <a href="#">Public Notices</a> <a href="#">Survey Form</a> <a href="#">Contact Us</a> <a href="#">E-Government</a> </div> <div id="main"> <h3>Countdown to Upcoming Events</h3> <table> <tr> <th colspan="2" style="text-align: right">Current Date and Time</th> <td><input name="thisDay" id="thisDay" readonly="readonly" size="40" /></td> </tr> <tr> <th>Event</th> <th>Starting Time</th> <th>Countdown to Event</th> </tr> <tr> <td><input value="Heritage Day" readonly="readonly" size="20" /></td> <td><input value="Jan 14 at 10:00 a.m." readonly="readonly" size="20" /></td> <td><input name="count1" id="count1" size="40" /></td> </tr> <tr> <td><input value="Spring Day Rally" readonly="readonly" size="20" /></td> <td><input value="May 21 at 12:00 p.m." readonly="readonly" size="20" /></td> <td><input name="count2" id="count2" size="40" /></td> </tr> <tr> <td><input value="July 4th Fireworks" readonly="readonly" size="20" /></td> <td><input value="Jul 4 at 9:00 p.m." readonly="readonly" size="20" /></td> <td><input name="count3" id="count3" size="40" /></td> </tr> <tr> <td><input value="Summer Bash" readonly="readonly" size="20" /></td> <td><input value="Sep 1 at 12:00 p.m." readonly="readonly" size="20" /></td> <td><input name="count4" id="count4" size="40" /></td> </tr><tr> <td><input value="Holiday Party" readonly="readonly" size="20" /></td> <td><input value="Dec 1 at 11:30 a.m." readonly="readonly" size="20" /></td> <td><input name="count5" id="count5" size="40" /></td> </tr> <tr> <td><input value="New Year's Bash" readonly="readonly" size="20" /></td> <td><input value="Dec 31 at 3:30 p.m." readonly="readonly" size="20" /></td> <td><input name="count6" id="count6" size="40" /></td> </tr> </table> </div> </form> </body> </html> Thanks for your help, I appreciate it |