JavaScript - Javascript Homework Assignment
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> Similar TutorialsHey, 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 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?
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? Hello, i have been trying to make a small one digit calculator, but i am having a lot of trouble with it..This is what i have so far. It will run each function individually, but if i try with all four sign functions, addition will only work....What am i doing wrong here? <!-- saved from url=(0014)about:internet --> <HTML> <HEAD> <TITLE>Page Title</TITLE> <SCRIPT language="JavaScript"> <!-- var n1 = -1; //1st operand of the expression -1 indicates n1 is empty var n2; //2st operand of the expression var startNew = true; var result; var operator; function readNumber(value) { if (n1 < 0) //n1 is empty { n1 = value; } else //n1 is not empty { n2 = value; } } function addition() { result = n1 + n2; //always deal with addition } function subtraction() { result = n1 - n2; //always deal with subtraction } function multiplication() { result = n1 * n2; //always deal with multiplication } function division() { result = n1 / n2; //always deal with division } function calculate_display() { //calculate the answer if (operator == '+') addition(); startNew = window.confirm(n1 + '+' + n2 + '=' + result + '\n' + ' start a new expression? '); if(startNew == true) //if ok is clicked { //clear n1 and n2 n1 = -1; n2 = -1; } { return; } if (operator == '-') subtraction(); startNew = window.confirm(n1 + '-' + n2 + '=' + result + '\n' + ' start a new expression? '); if(startNew == true) //if ok is clicked { //clear n1 and n2 n1 = -1; n2 = -1; } { return; } if (operator == '*') multiplication(); startNew = window.confirm(n1 + '*' + n2 + '=' + result + '\n' + ' start a new expression? '); if(startNew == true) //if ok is clicked { //clear n1 and n2 n1 = -1; n2 = -1; } { return; } if (operator == '-') division(); startNew = window.confirm(n1 + '/' + n2 + '=' + result + '\n' + ' start a new expression? '); if(startNew == true) //if ok is clicked { //clear n1 and n2 n1 = -1; n2 = -1; } { return; } } //--> </SCRIPT> </HEAD> <BODY> <form> <input type = "button" value="0" onclick="readNumber(0);"> <input type = "button" value="1" onclick="readNumber(1);"> <input type = "button" value="2" onclick="readNumber(2);"> <input type = "button" value="3" onclick="readNumber(3);"> <input type = "button" value="4" onclick="readNumber(4);"> <BR> <input type = "button" value="5" onclick="readNumber(5);"> <input type = "button" value="6" onclick="readNumber(6);"> <input type = "button" value="7" onclick="readNumber(7);"> <input type = "button" value="8" onclick="readNumber(8);"> <input type = "button" value="9" onclick="readNumber(9);"> <BR> <input type = "button" value="+" onclick="operator = '+';"> <input type = "button" value="-" onclick="operator = '-';"> <input type = "button" value="*" onclick="operator = '*';"> <input type = "button" value="/" onclick="operator = '/';"> <input type = "button" value="=" onclick="calculate_display();"> </form> 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 coding forum users, I am working on the only javascript chapter of my HTML textbook. It asks me to: Quote: replace the line <img id="sky" src="sky0.jpg" alt=""/> with a script element that writes the following HTML code: <img id='sky' src='mapNum.jpg' alt=' ' /> where mapNum is the value of the mapNum variable. so I try PHP Code: <script type="text/javascript" /> document.write("<img id='sky' src='mapNum.jpg' alt=' ' />") </script> after a few other attempts I search codingforums and find: PHP Code: document.write("<img id=\"sky\" src='sky"+mapNum+".jpg' alt='' />"); and PHP Code: document.write('<img id="sky" src="sky'+mapNum+'.jpg" alt="" />'); and these work perfectly fine but I don't understand why? my textbook only has one javascript chapter and its really small and vague, and my teacher hasn't answered my emails, so I would be grateful if anyone can tell my why my first code falls flat. I need desperate help with a homework! Here's the task: First of all I need to define an array of 3 elements. Each element is associated with a different first name. Then I shall realize a first function to add a name in the table. The function takes as parameter the table previously created and return it containing an additional element whose value is the name that the visitor wants to add. I must use the dialog box prompt so that the user can specify the name he wishes to add in the table. I shall also perform a second function which will display the name that is included in the different array elements. This function will also take the table in parameters and proceed with setting the display name with a dialog box alert type that contains all of the name separated by ";". Here's what I've done so far: HTML Code: Code: <html> <head> <title> Task #4 </title> </head> <body> <script language="javascript"> function addName() { var names=new Array(3); names[0]="John"; names[1]="Patrik"; names[2]="Jane"; document.open(); document.write(names[3].join()); document.close(); if(names==new Array); { prompt("What name do you want to add?"+""); } return addName } </script> <noscript> <h1> You're browser doesn't support Javascript </h1> </noscript> </body> </html> I don't really understand the second part of the task, but the first part is what I've written but it doesn't seem to do anything when I try it on my browser. What am I doing wrong? Thank you for your patience. -A Javascript newbie hi I need some help with a project I am working on. I spent time with my instructor but I lost something in translation. I know this is really basic but I really can't see what is wrong. we are trying to open employee payroll records and if the employee works 35hrs or less they get straight pay. anything over 35 is time and a half. I though my calculations were correct but if you calculate the first four records, which I wll post after the code, they are wrong. here is my code, Code: //constants var THIRTYFIVE = 35; var ONE_POINT_FIVE = 1.5; var ZERO = 0; //global variables var employeeNumber; var employeeName; var hourlyWage; var hoursWorked; var grossPay; var partOne; var partTwo; var totalForEmployee; var counter; var records; partOne = ZERO; partTwo = ZERO; totalForEmployee = 0; function calculateGrossPay() { while (records.readNextRecord()) { employeeNumber = records.getEmployeeNumber(); employeeName = records.getEmployeeName(); hourlyWage = records.getEmployeeHourlyWage(); hoursWorked = records.getEmployeeHoursWorked(); if (hoursWorked <= THIRTYFIVE) { partOne = hoursWorked * hourlyWage; } else { partOne = (hourlyWage * THIRTYFIVE); partTwo = ((hoursWorked - THIRTYFIVE) * hourlyWage) * ONE_POINT_FIVE; } totalForEmployee = partOne + partTwo; document.write(employeeNumber + "\t" + "\t" + employeeName + "\t" + totalForEmployee + "<br />"); } } /* this function prints the top row of the table */ function printHeader() { document.write("Employee" + "\t" + "Employee" + "\t" + "Gross" + "\t" + "\t" + "Withholding" + "\t" + "Net" + "\t" + "<br />" + "Number" + "\t" + "\t" + "Name" + "\t" + "\t" + "Pay" + "\t" + "\t" + "Amount" + "\t" + "\t" + "Pay" + "<br />" + "<br />"); } /* this function opens employee payroll records */ function initializeEmployeePayrollRecords() { records = openEmployeePayrollRecords(); } /* Design a program that will process the weekly employee time cards for all the employees of an organization. Each employee time card will have the these data items: an employee number, an employee name, an hourly wage rate, and the number hours worked during the week. Each employee is to be paid time-and-a-half for all hours worked over 35. A tax amount of 15% of gross salary is to be withheld. The output to the screen should display the employee's number and name, gross pay, withholding amount, and net pay. At the end of the report, display the total gross payroll amount, the total net payroll amount, and the average net pay paid per employee. */ function project4Part2() { // Your code goes in here. initializeEmployeePayrollRecords(); printHeader(); calculateGrossPay(); } this is the output I am getting Employee Employee Gross Withholding Net Number Name Pay Amount Pay 101 Joe Coyne 581.25 102 Fred Hensen 716.25 103 Ethel Roselle 1250 104 Barney Curry 1425 this is from the dataset, the first number is the wage, the second is the hours worked. 101 Joe Coyne 15 37.5 102 Fred Hensen 20 33 103 Ethel Roselle 25 45 104 Barney Curry 30 35 I would really appreciate any help with this, I am sure the answer is really simple but I am past the point of frustration. I am Having trouble getting this function to work. I am suppose to add javascript to a page to access an external js file named random.js to generate 5 random numbers when the page loads. it isnt doing it so far. Here is what i have. <html> <head> <script type="text/javascript" src="random.js"></script> <script type="text/javascript"> function showImg(o.jpg-9.jpg){ /* The showImg() function displays a random image from the 0.jpg through 9.jpg files. The random image is designed to thwart hackers attempting to endter the library database by requiring visual confirmation. */ var imgNumber= randomInteger(9);// Return a random number from 0 to 9. document.write("<img src='"+imgNumber+".jpg' alt='"+imgNumber+".jpg'/>"); } </script> </head> (<tr> <td colspan="2" class="center"> <script type= "text/javascript"> showlmg(); showlmg(); showlmg(); showlmg(); showlmg(); </script> </td> </tr> I have no clue where to start. I have to put a pop up box on the screen and have the user enter a number under 100 and tell them how many quarters dimes nickles and pennies that would be. PLEASE HELP I am stumped
I need help with trying to figure out what exactly needs to be done with both of these homework assignments. Nothing we covered in the textbook or examples provided go along with these directions so I am at a lost. For one assignment we need to: Write a JavaScript script within a web page that will use prompt/alert dialog boxes to calculate an average value for a list of numbers that could be any size. Use a while loop that will prompt a user for a number. As long as the number is not zero or negative, continue to add the numbers up and count the total number of values entered. Once the user enters a zero or negative value, terminate the loop and calculate the average. Report this final value via an alert box. For the other assignment we need to: Write a JavaScript script that first asks the user to enter an integer value from 1..15. Validate this with an error checking that will not allow them to continue until they enter a proper number. After the input is validated, use this number to dynamically build an HTML table using a JavaScript loop with one row and including a number of columns matching the user input. Can someone please help me out on how I should go about coding for these two assignments, I am at a loss with these assignments. I have a homework page with three schools , four classes, and 4 weeks. Thing is I can't get the assignments to come up in the assignments text area. I can if I only have two if...else conditions, and I have tried three with nesting, but it always comes up undefined. This is for a class assignment but I really need help. I commented out the codes that didn't work. Sometimes i didn't finish the whole code before testing so is that maybe why it didn't work? Must it be complete to work? Thanks in advance for any help. I put the whole page in. I am very new to this, and i just can't get my head around it, so any help would be apreciated. It worked if all assignments as long as the assignments were the same for each class of each school. Daisey Code: <!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>functions</title> <script language="javascript"> function test2(form){ /*create a variable*/ var varSchool = form.ddlSchool.value var varClass = form.ddlClass.value var varWeek = form.ddlWeek.value var varResults /*create an if statement to determine school*/ if (varSchool==0){ varSchool = "Prairie High School's "; } else if (varSchool==1){ varSchool = "Prairie Middle School's "; } else if (varSchool==2){ varSchool = "Prairie Elementary School's "; } if (varSchool==0) { if ((varClass==0) && (varWeek==0)){ varResults = "000 this code works"; }else if ((varClass==0) && (varWeek==1)){ varResults = "001 this code works"; }else if ((varClass==0) && (varWeek==2)){ varResults = "002 this code works"; }else if ((varClass==0) && (varWeek==3)){ varResults = "003 this code works"; }else if ((varClass==1) && (varWeek==0)){ varResults = "010 this code works"; }else if ((varClass==1) && (varWeek==1)){ varResults = "011 this code works"; }else if ((varClass==1) && (varWeek==2)){ varResults = "012 this code works"; }else if ((varClass==1) && (varWeek==3)){ varResults = "013 this code works"; }else if ((varClass==2) && (varWeek==0)){ varResults = "020 this code works"; }else if ((varClass==2) && (varWeek==1)){ varResults = "021 this code works"; }else if ((varClass==2) && (varWeek==2)){ varResults = "022 this code works"; }else if ((varClass==2) && (varWeek==3)){ varResults = "023 this code works"; }else if ((varClass==3) && (varWeek==0)){ varResults = "030 this code works"; }else if ((varClass==3) && (varWeek==1)){ varResults = "031 this code works"; }else if ((varClass==3) && (varWeek==2)){ varResults = "032 this code works"; }else if ((varClass==3) && (varWeek==3)){ varResults = "033 this code works"; } } else if (varSchool==1) { if ((varClass==0) && (varWeek==0)){ varResults = "100 this code works"; }else if ((varClass==0) && (varWeek==1)){ varResults = "101 this code works"; }else if ((varClass==0) && (varWeek==2)){ varResults = "102 this code works"; }else if ((varClass==0) && (varWeek==3)){ varResults = "103 this code works"; }else if ((varClass==1) && (varWeek==0)){ varResults = "110 this code works"; }else if ((varClass==1) && (varWeek==1)){ varResults = "111 this code works"; }else if ((varClass==1) && (varWeek==2)){ varResults = "112 this code works"; }else if ((varClass==1) && (varWeek==3)){ varResults = "113 this code works"; }else if ((varClass==2) && (varWeek==0)){ varResults = "120 this code works"; }else if ((varClass==2) && (varWeek==1)){ varResults = "121 this code works"; }else if ((varClass==2) && (varWeek==2)){ varResults = "122 this code works"; }else if ((varClass==2) && (varWeek==3)){ varResults = "123 this code works"; }else if ((varClass==3) && (varWeek==0)){ varResults = "130 this code works"; }else if ((varClass==3) && (varWeek==1)){ varResults = "131 this code works"; }else if ((varClass==3) && (varWeek==2)){ varResults = "132 this code works"; }else if ((varClass==3) && (varWeek==3)){ varResults = "133 this code works"; } } else (varSchool==2) { if ((varClass==0) && (varWeek==0)){ varResults = "200 this code works"; }else if ((varClass==0) && (varWeek==1)){ varResults = "201 this code works"; }else if ((varClass==0) && (varWeek==2)){ varResults = "202 this code works"; }else if ((varClass==0) && (varWeek==3)){ varResults = "203 this code works"; }else if ((varClass==1) && (varWeek==0)){ varResults = "210 this code works"; }else if ((varClass==1) && (varWeek==1)){ varResults = "211 this code works"; }else if ((varClass==1) && (varWeek==2)){ varResults = "212 this code works"; }else if ((varClass==1) && (varWeek==3)){ varResults = "213 this code works"; }else if ((varClass==2) && (varWeek==0)){ varResults = "220 this code works"; }else if ((varClass==2) && (varWeek==1)){ varResults = "221 this code works"; }else if ((varClass==2) && (varWeek==2)){ varResults = "222 this code works"; }else if ((varClass==2) && (varWeek==3)){ varResults = "223 this code works"; }else if ((varClass==3) && (varWeek==0)){ varResults = "230 this code works"; }else if ((varClass==3) && (varWeek==1)){ varResults = "231 this code works"; }else if ((varClass==3) && (varWeek==2)){ varResults = "232 this code works"; }else if ((varClass==3) && (varWeek==3)){ varResults = "233 this code works"; } } /* make a conditional assignment variable with two conditions class and week*/ /*var varscClass if ((varSchool == 0) && (varClass == 0)){ varscClass == 0 }else if ((varSchool == 0) && (varClass == 1)){ varscClass == 1 }else if ((varSchool == 0) && (varClass == 2)){ varscClass == 2 }else if ((varSchool == 0) && (varClass == 3)){ varscClass == 3 }else if ((varSchool == 1) && (varClass == 0)){ varscClass == 4 }else if ((varSchool == 1) && (varClass == 1)){ varscClass == 5 }else if ((varSchool == 1) && (varClass == 2)){ varscClass == 6 }else if ((varSchool == 1) && (varClass == 3)){ varscClass == 7 }else if ((varSchool == 2) && ( varClass == 0)){ varscClass == 8 }else if ((varSchool == 2) && ( varClass == 1)){ varscClass == 9 }else if ((varSchool == 2) && ( varClass == 2)){ varscClass == 10 }else if ((varSchool == 2) && ( varClass == 3)){ varscClass == 11 }*/ /*if ((varscClass == 0) && (varWeek == 0)){ classWeekassign = "week 1 of reading is read Chapter 1." }else if ((varscClass == 0) && (varWeek == 1)){ classWeekassign = "week 2 of reading is complete the Chapter 1 Review, page 20." }else if ((varscClass == 0) && (varWeek == 2)){ classWeekassign = "week 3 of reading is read Chapter 2." }else if ((varscClass == 0) && (varWeek == 3)){ classWeekassign = "week 4 of reading is complete the Chapter 3 Review, page 40." }else if ((varscClass == 1) && (varWeek == 0)){ classWeekassign = "week 1 of math is complete the Chapter 3 Review, page 40." }else if ((varscClass == 1) && (varWeek == 1)){ classWeekassign = "week 2 of math is complete the Chapter 3 Review, page 40." }else if ((varscClass == 1) && (varWeek == 2)){ classWeekassign = "week 3 of math is complete the Chapter 3 Review, page 40." }else if ((varscClass == 1) && (varWeek == 3)){ classWeekassign = "week 4 of math is complete the Chapter 3 Review, page 40." }*/ /*do a switch to determine favorite color*/ switch(varClass){ case "0": varResults = varSchool + "reading assignment for "; break; case "1": varResults = varSchool + "math assignment for "; break; case "2": varResults = varSchool + "science assignment for "; break; case "3": varResults = varSchool + "english assignment for "; } var classWeekassign /*another attempt failed if (varSchool==0) { if (varClass==0) { if (varWeek==0){ classWeekassign = "week 1 is to read Chapter 1." } else if(varWeek!=0){ } } else if((varClass==0) && (varWeek==1)){ classWeekassign = "week 1 of reading is do the Chapter 1 Review, page 20." } else if((varClass==0) && (varWeek==2)){ classWeekassign = "week 3 of reading is read Chapter 2." } else if((varClass==0) && (varWeek==3)){ classWeekassign = "week 4 of reading is do the Chapter 2 Review, page 40." } } else if(varSchool==1){ } */ /*Concatenate a string*/ varResults = varResults + classWeekassign; /*Write to the page*/ form.txtResults.value = varResults + classWeekassign; } </script> </head> <body> <form id="myform" action="" method="get"> <table> <tr> <td colspan="2"><p> <select name="ddlSchool"> <option value="0">Prairie High School</option> <option value="1">Prairie Middle School</option> <option value="2">Prairie Elementary School</option> </select> <select name="ddlClass"> <option value="0">Reading</option> <option value="1">Math</option> <option value="2">Science</option> <option value="3">English</option> </select> <br /> </p></td> </tr> <tr> <td width="223"> <select name="ddlWeek"> <option value="0">Week 1</option> <option value="1">Week 2</option> <option value="2">Week 3</option> <option value="3">Week 4</option> </select></td> <td width="147"><input name="btnSubmit" type="button" value="Submit" onclick="test2(this.form)" /></td> </tr> <tr> <td colspan="2"><textarea name="txtResults" cols="50" rows="3"></textarea> </td> </tr> </table> </form> </body> </html> 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!!!!!!!!!!!! =) Hello all, I’ve got a homework to do and I'm stuck, as you can see i have done all the function's (i think they are ok but not shure) with a main program I'm stuck don’t know even where to begin :/ could anyone please please help a bit? best regards <HTML> <HEAD> <TITLE> The game of 21 </TITLE> <SCRIPT LANGUAGE = "JavaScript"> //FUNCTIONS /* *removes a given number of sticks * *function takes one argument numberToRemove that represents the number of sticks to be removed * if numberToRemove is more than numberOfSticks, reduces numberOfSticks to 0 * otherwise reduces numberOfSticks by numberToRemove *function returns no value */ function removeSticks(numberToRemove) { if (numberOfSticks< numberToRemove) { numberOfSticks =0 } else { (numberOfSticks = numberOfSticks - numberToRemove); } } /* *switches current player * *function takes no argument * if current player is 1, sets current player to 2 * otherwise sets current player to 1 *function returns no value */ function switchCurrentPlayer() { if (currentPlayer ==1) { return currentPlayer = 2; } { return currentPlayer = 1; } } /* *gets a number from a prompt dialogue * *function takes no argument * prompts the current player for a number of sticks to remove, with a suitable message *function returns the number the player enters */ function getChosenNumber() { ChosenNumber = window.prompt('Player ' + currentPlayer + ': Please enter either 1, 2 OR 3.'); return ChosenNumber; } //VARIABLES -- do not change this section var numberOfSticks = 21;//number of matchsticks, initially 21 var currentPlayer = 1;//player whose turn it is, Player 1 goes first var numberChosen;//variable used to hold the number the current player chooses //MAIN PROGRAM The players take turns to choose how many matches to remove, as long as there are still matches left. After each go the program outputs the number of matches that still remain and if this number is zero a message is displayed to say the current player is the winner. The turn then passes to the other player. </SCRIPT> </HEAD> <BODY> </BODY> </HTML> 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. |