JavaScript - Please Help I Am Trying To Create A Program To Run Then Repeat Askingi
import javax.swing.JOptionPane;
class TriangleArea { public static void main(String[] args) { //delcare variable for main String Area = "a"; //get user input and convert to integers String firstNumber = JOptionPane.showInputDialog( "Enter first value for height" ); String secondNumber = JOptionPane.showInputDialog( "Enter second value for base" ); //call Methodname String CallBack = "double number1 + double number2"; double number1 = Double.parseDouble( firstNumber ); double number2 = Double.parseDouble( secondNumber ); double total = number1 * number2 * 0.5; JOptionPane.showMessageDialog(null… "Height : " + number1+" " + "Base : " + +number2+" " + "Area : " +total); //end Methodname System.exit(0); } public static void calcArea (Double number1, Double number2) { int c=0; String total="dummy"; //declare tocal variables String CallBack = "double number1 + double number2"; //display result while(c == 0) JOptionPane.showMessageDialog(null… "Height : " + number1+" " + "Base : " + +number2+" " + "Area : " +total); } } I am trying to create a program that will run and repeat asking user for another input. The program is work but i cannot get the while loop or to ask user to enter another input to work. Please help. Similar TutorialsSorry for the stupid question but i can't find a specific answer and i'm a newby. Here is a example of what i have: <html> <head> <script type="text/javascript"> function open_win() {window.open("http://www.microsoft.com","Window1","menubar=no,width=660,height=300,toolbar=no,scrollbars=yes");} </script> </head> <body> <form> <input type=button value="Open Window" onclick="open_win()"> </form> </body> In stead of a button to open one window, i would like a numeric input box that asks "How many windows do you want to open?" then incorporate a loop command to loop the open_win() x amount of times. Any help would be appreciated. Thanks I'd like to request this thread be moved to the PHP area. Thank you! Hello, I confess, I'm a javascript newbie, but I have a project dilemma that is beyond my capabilities. I'm building a web based scoring system. I will input players names and their individual scores. Each of their 12 "station" scores will be placed into 12 text boxes and the total will be added up and placed into a textbox called Score. I've started with only two textboxes to start out and here is what I have (which works). Code: <HTML> <HEAD> <script type="text/javascript"> function popup(form) { var Box1 = document.scoreform.one.value; var Box2 = document.scoreform.two.value; form.Score.value =(Number(Box1) + Number(Box2)); } </script> </HEAD> <BODY> <table width="980" border="0" cellspacing="0" cellpadding="0"> <tr> <td><FORM ACTION="#" NAME="scoreform" id="scoreform"> Station 1 <INPUT NAME="one" TYPE=TEXT id="one" ONCHANGE="popup(form)" value="<?php echo $row_Recordset1['one']; ?>" > Station 2 <INPUT NAME="two" TYPE=TEXT id="two" ONCHANGE="popup(form)" value="<?php echo $row_Recordset1['two']; ?>"> Score <input type=TEXT name="Score" readonly id="Score"> <BR> </FORM></td> </tr> </table> </BODY> </HTML> My dilemma is when I place a php repeat region (thanks dreamweaver) around this table, nothing works. I think the form needs to have a unique identity but I don't know how to execute it properly. Here's the code that doesn't work. Code: <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } mysql_select_db($database_mooren, $mooren); $query_Recordset1 = "SELECT * FROM SIGNUP_NSCA"; $Recordset1 = mysql_query($query_Recordset1, $mooren) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); ?> <HTML> <HEAD> <script type="text/javascript"> function popup(form) { var Box1 = document.scoreform.one.value; var Box2 = document.scoreform.two.value; form.Score.value =(Number(Box1) + Number(Box2)); } </script> </HEAD> <BODY> <?php do { ?> <table width="980" border="0" cellspacing="0" cellpadding="0"> <tr> <td><FORM ACTION="#" NAME="scoreform" id="scoreform"> Station 1 <INPUT NAME="one" TYPE=TEXT id="one" ONCHANGE="popup(form)" value="<?php echo $row_Recordset1['one']; ?>" > Station 2 <INPUT NAME="two" TYPE=TEXT id="two" ONCHANGE="popup(form)" value="<?php echo $row_Recordset1['two']; ?>"> Score <input type=TEXT name="Score" readonly id="Score"> <BR> </FORM></td> </tr> </table> <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?> </BODY> </HTML> <?php mysql_free_result($Recordset1); ?> Thank you for any assistance! I am using the counter script below to display a count from 1-36. Does anyone know how to edit the javascript to flash or blink the number 36 a few times, and then loop the script to start over and count from 1-36 again (and again)? Here's the script: <html> <head> <title></title> </head> <script type="text/javascript"> var t, max, i; function Increase(amount) { max = amount; i = parseInt(document.getElementById("count").value); t = setInterval("SetIncrease()", 500); } function SetIncrease() { document.getElementById("count").value = ++i; if(i == max) { clearTimeout(t); } } </script> <body onLoad="Increase(36);"> <input id="count" type="text" value="1" style="width:40px;font-family:georgia;font-size:30px;font-weight:bold;color:#CC0000;border: 0px solid #000000;text-align:right;background-color:#FFFF00;" align="center"> </body> </html> Many thanks! I've looked everywhere for a random number generator which doesn't repeat. Tried loads and none have seemed to work. I'm making a quiz, 5 questions so far. This button, in html, generates the next random Q: Code: <input type="button" value="Next (random)" name="B0" onClick="rangen();generatequestions();qnum()"><br><br> Lower down in the javascript (in the body), here is the rangen() function: Code: function rangen(){ whichone=Math.floor(Math.random()*5) } But I need a random generator which fires them off only once. For reference, here is the next bit (not so important): Code: var whichone=1; var q=1; var tempmn=document.instantquiz.thequestion function generatequestions(){ if (q>0) q=q++ if (loop>0) loop=0 document.instantquiz.theresponse.selectedIndex=0 if (!document.instantquiz.cmode.checked||whichone>=total+1||whichone<=0) document.instantquiz.thesolution.value='' if (whichone>=total+1) tempmn.value="End of quiz" else{ tempmn.value=whichone+")"+question[whichone]+"\n\n"+"a)"+eval('choice'+whichone+'[1]')+"\n"+"b)"+eval('choice'+whichone+'[2]' )+"\n"+"c)"+eval('choice'+whichone+'[3]')+"\n"+"d)"+eval('choice'+whichone+'[4]') if (document.instantquiz.cmode.checked) document.instantquiz.thesolution.value=solution[whichone] } } Anyone have suggestions for a non-repeating random number gen which will work? Even the one now seems to have some slight error associated with it. The one's ive tried so far haven't worked.. Hi there! i want to know, what should I do to make the j query simple slide show repeat playing as currently it stops when the slide show finishes. How can I do it repetitive? My array contains 15 value I want to random pick 5 value: Code: myArray[0] ="a"; myArray[1] ="b"; myArray[2] ="c"; myArray[3] ="d"; myArray[4] ="e"; myArray[5] ="f"; myArray[6] ="g"; myArray[7] ="h"; myArray[8] ="i"; myArray[9] ="j"; myArray[10] ="k"; myArray[11] ="l"; myArray[12] ="a"; myArray[13] ="b"; myArray[14] ="c"; How to random pick from all elements with no repeat of the same content. e.g. if myArray[0] is picked then myArray[12] will not be picked again. (because they have the same value "a") I need a count down clock that will count down 18 minutes and reset itself at the end. also i need a counter that increases by +1 every 18 minutes starting at 0. thankyou Hello everyone. This is my first program. According to the idea of a program that calculates the sum of savings with the bank interest rates that is paid each year. And I put one amount every month. The question is very simple why full = 0? Code: var years = prompt("How many years will accumulate?)"); var prec = prompt("And how many % bank give?"); var income = prompt("How many you will put off in bank?"); var num = 12; var full = 0; months=years*num; console.log("Altogether we get " + years + " years and " + months + " months.") for (var month = 0; month == months; month++) { if (month % num == 0) { full = full + income + (full*prec/100); } else { full = full + income; } } console.log("Total accumulated =" + full); Reply With Quote 01-24-2015, 04:37 PM #2 leonfresh View Profile View Forum Posts New to the CF scene Join Date Jan 2015 Posts 8 Thanks 0 Thanked 0 Times in 0 Posts var full = 0 declares the variable as an integer variable. it's important to do so to avoid declaration errors. Reply With Quote 01-24-2015, 05:09 PM #3 jmrker View Profile View Forum Posts Senior Coder Join Date Aug 2006 Location FL Posts 3,175 Thanks 39 Thanked 510 Times in 504 Posts You have a logic problem. Try... Code: for (var month = 0; month<months; month++) { Also note that your logic applies the full percentage at the 1st month of the loan/deposit. Is this what your really intended? Reply With Quote Users who have thanked jmrker for this post: Nadir+ (01-24-2015) 01-24-2015, 06:28 PM #4 Nadir+ View Profile View Forum Posts New to the CF scene Join Date Jan 2015 Posts 6 Thanks 1 Thanked 0 Times in 0 Posts i catch another problem, when i change this Code: for (var month = 0; month == months; month++) { on this, Code: for (var month = 0; month<months; month++) { program started work. But in rusults see this . Code: Altogether we get 1 years and 12 months. Total accumulated =01000100100100100100100100100100100100 all code there Code: var years = prompt("How many years will accumulate?)"); var prec = prompt("And how many % bank give?"); var income = prompt("How many you will put off in bank?"); var num = 12; var full = 0; months=years*num; console.log("Altogether we get " + years + " years and " + months + " months.") for (var month = 0; month < months; month++) { if (month % num == 0) { full = full + income + (full*prec/100); } else { full = full + income; } } console.log("Total accumulated =" + full); Reply With Quote 01-24-2015, 06:39 PM #5 Nadir+ View Profile View Forum Posts New to the CF scene Join Date Jan 2015 Posts 6 Thanks 1 Thanked 0 Times in 0 Posts i realized something if i delete var income and just put in its place 100, program work almost normal. Code: Altogether we get 2 years and 24 months. main.js:17 Total accumulated =2520 But if i write 1 year it dont work,how can i fix it? Code: Altogether we get 1 years and 12 months. main.js:17 Total accumulated =1200 Reply With Quote 01-24-2015, 09:42 PM #6 Old Pedant View Profile View Forum Posts Supreme Master coder! Join Date Feb 2009 Posts 28,310 Thanks 82 Thanked 4,754 Times in 4,716 Posts The value you get from a call to prompt() is *ALWAYS* a string. When you use the + operator with a string, it does *NOT* do addition; it does string concatenation. You just need to convert all those prompt() results to numbers: Code: var years = Number( prompt("How many years will accumulate?") ); var prec = Number( prompt("And how many % bank give?") ); var income = Number( prompt("How many you will put off in bank?") ); Also, you need to do Code: for (var month = 0; month <= months; month++) { else you will only do (for example) up to month 23 when the user asks for 2 years. Be aware that prompt() and confirm() and console.log() are considered VERY obsolete and should only be used for debugging purposes, not for real web code. I have an assignment to create a program in JS but I have not read JS much more. So, for this assignment, can anyone help me to solve this assignment? Check attachment. Uploaded with ImageShack.us This is my code from prelim to finals. The missing part here is when the input is less than or equal to 65 and greater than 100, the prompt will say INVALID ENTRY. However, after it says Invalid Entry, it must ask you to enter again an Entry until you input a valid entry. It must be terminated after you input from prelim to finals either 0,20,30,40 or after you input a valid entry and after the program calculated it. My program does not terminate after I input valid entries. It just continue to ask grade again and again even it already calculated the grades. I don't know how will I put those code inside the program. I'm getting really confused. Code: <html> <head> <title>Web Programming Laboratory Exam</title> </head> <body> <script language="JavaScript"> do { { var pg=prompt('Enter Prelim Grade','0'); if(pg==0) { alert('No Grade'); document.write('<br>Prelim Grade is '+pg); } else if(pg==20) { alert('Not Attending'); document.write('<br>Prelim Grade is '+pg); } else if(pg==30) { alert('Dropped'); document.write('<br>Prelim Grade is '+pg); } else if(pg==40) { alert('Incomplete'); document.write('<br>Prelim Grade is '+pg); } else document.write('Prelim Grade is '+pg); var mg=prompt('Enter Midterm Grade','0'); } { if(mg==0) { alert('No Grade'); document.write('<br>Midterm Grade is '+mg); } else if(mg==20) { alert('Not Attending'); document.write('<br>Midterm Grade is '+mg); } else if(mg==30) { alert('Dropped'); document.write('<br>Midterm Grade is '+mg); } else if(mg==40) { alert('Incomplete'); document.write('<br>Midterm Grade is '+mg); } else document.write('</br>Midterm Grade is '+mg); var fg=prompt('Enter Final Grade','0'); } { if(fg==0) { alert('No Grade'); document.write('<br>Final Grade is '+fg); } else if(fg==20) { alert('Not Attending'); document.write('<br>Final Grade is '+fg); } else if(fg==30) { alert('Dropped'); document.write('<br>Final Grade is '+fg); } else if(fg==40) { alert('Incomplete'); document.write('<br>Final Grade is '+fg); } else { document.write('</br>Final Grade is '+fg); sg=((pg*.3)+(mg*.3)+(fg*.4)); document.write('<br>Your Semestral Grade is '+sg); } } if (sg>=74.5) { document.write('<br>Remarks: Passed'); document.write('</br>This Program is developed by -k3nN'); } else if (sg<74.5) { document.write('<br>Remarks:Failed'); document.write('</br>This Program is developed by -k3nN'); } } while (sg>=74.5|sg<74.5) { document.write('</br>Thanks') } </script> </body> </html> For class NumericQuestion Add setAnswer, a method that takes a double as input, converts it to a string and calls setAnswer in the superclass Question to store the answer. o Add checkAnswer, a method that takes an answer in string form, converts it to a double, gets the correct answer in string form from Question, converts it to a double, and returns true if they are within 0.01 of each other and false otherwise. For class quiz Change main so that all three questions are asked. presentQuestion that prints out the correct answer, only when the answer is wrong public class NumericQuestion { private String text; private Double answer; /** * Constructs a question with empty question and answer. */ public NumericQuestion() { text = ""; answer = 3.1416; } /** * Sets the question text. * @param questionText the text of this question */ public void setText(String questionText) { text = questionText; } /** * Sets the answer for this question. * @param correctResponse the answer */ public void setAnswer(Double correctResponse) { answer = correctResponse; } /** * Checks a given response for correctness. * @param response the response to check * @return true if the response was correct, false otherwise */ public boolean checkAnswer(String response) { return response.equals(answer); } /** * Displays this question. */ public void display() { System.out.println(text); } } import java.util.Scanner; public class Quiz { public static void main(String[] args) { Question first = new Question(); first.setText("What inherits data and behavior from a superclass?"); first.setAnswer("subclass"); ChoiceQuestion second = new ChoiceQuestion(); second.setText("Which modifies the object on which it operates in some way?"); second.addChoice("Accessor", false); second.addChoice("Mutator", true); second.addChoice("Method", false); second.addChoice("Variable", false); NumericQuestion third = new NumericQuestion(); third.setText("What is the numeric value for PI?"); third.setAnswer(3.1416); presentQuestion(first); presentQuestion(second); //presentQuestion(third); } /** Presents a question to the user and checks the response. @param q the question */ public static void presentQuestion(Question q) { q.display(); System.out.print("Your answer: "); Scanner in = new Scanner(System.in); String response = in.nextLine(); System.out.println(q.checkAnswer(response)); } } im looking to make a program for my site to where somebody can type something in and it will go onto a image like a userbar and then they can save that image with the txt the choose to go over it, does anybody have any advice for me to use? I'm very new at Javascript and writing programs so I'm not sure if this is even possible to do. I want to write a program that allows someone to select four tasks from a dropdown menu. The tasks are each 1 hour long. I want the program to calculate the number of hours and display that information below the tasks. I also want the person to be able to add or remove tasks. I get how to save tasks and display the results but I don't know how to calcuate the number of hours. Any suggestions? Here is what I have so far: Code: <!doctype html> <html> <head> <meta charset="utf-8"> <title>Four Tasks</title> <style> body { background-color:silver; font-family:Arial, Helvetica, sans-serif; font-size:1.2em; } h1 { font-family:Arial, Helvetica, sans-serif; font-size:1.4em; } </style> <script> function storeTask(task) { var taskDetail = document.getElementById(task).value; localStorage.setItem(task, taskDetail); } function getTask(task) { document.getElementById(task).value = localStorage.getItem(task); } function clearTask(task) { localStorage.removeItem(task); document.getElementById(task).value=""; } function displayTasks() { outputResults = document.getElementById("Results"); outputResults.innerHTML = 'Task 1: ' + localStorage.getItem('task1') + '<br />' + 'Task 2: ' + localStorage.getItem('task2') + '<br />' + 'Task 3: ' + localStorage.getItem('task3') + '<br />' + 'Task 4: ' + localStorage.getItem('task4') + '<br />' + ''; } </script> </head> <body> <table width="100%"> <tr> <td valign="top"> <div id="outer"> <h1>Four Tasks</h1> My To Do List: <br><br> Task 1: <select id="task1"> <option>Laundry</option> <option>Cooking</option> <option>Dishes</option> <option>Water Plants</option> <input type="button" value="Save" onclick="storeTask('task1');"> <input type="button" value="Clear" onclick="clearTask('task1');"> <br><br> Task 2: <select id="task2"> <option>Laundry</option> <option>Cooking</option> <option>Dishes</option> <option>Water Plants</option> <input type="button" value="Save" onclick="storeTask('task2');"> <input type="button" value="Clear" onclick="clearTask('task2');"> <br><br> Task 3: <select id="task3"> <option>Laundry</option> <option>Cooking</option> <option>Dishes</option> <option>Water Plants</option> <input type="button" value="Save" onclick="storeTask('task3');"> <input type="button" value="Clear" onclick="clearTask('task3');"> <br><br> Task 4: <select id="task4"> <option>Laundry</option> <option>Cooking</option> <option>Dishes</option> <option>Water Plants</option> <input type="button" value="Save" onclick="storeTask('task4');"> <input type="button" value="Clear" onclick="clearTask('task4');"> </div> </td> <td valign="top"> My Tasks: <br> <input type="button" value="Display tasks" onclick="displayTasks();"> <div id="Results"></div> </td> </tr> </table> </body> </html> I wrote about this script a couple weeks ago. I stopped working on it, and just got on it today. Question, what's the easiest way to have it so Monday, tuesday, Wednesday, etc and then the total amount of hours gets added. Code: <html> <head> <script language="JavaScript" src="gen_validatorv5-.js" type="text/javascript" xml:space="preserve"></script> <script type="text/javascript"> function calc(nForm){ var inHour =parseInt( nForm.inHr.value) var inMinutes = parseInt( nForm.inMin.value); var lunchOutHour = parseInt(nForm.lunchOutHr.value); var lunchOutMinutes = parseInt( nForm.lunchOutMin.value); var lunchInHour = parseInt( nForm.lunchInHr.value); var lunchInMinutes = parseInt( nForm.lunchInMin.value); var outHour = parseInt( nForm.outHr.value); var outMinutes = parseInt( nForm.outMin.value); var linearInTime = 60*(inHour)+(inMinutes); var linearLunchOutTime = 60*(lunchOutHour)+(lunchOutMinutes); var linearLunchInTime = 60*(lunchInHour)+(lunchInMinutes); var linearOutTime = 60*(outHour)+(outMinutes); var workDay = linearOutTime-linearInTime; var lunchPeriod = linearLunchInTime-linearLunchOutTime; var linearMinutesWorked = workDay-lunchPeriod; var hoursWorked = parseInt(linearMinutesWorked/60); var minutesWorked = linearMinutesWorked-(hoursWorked*60) if (hoursWorked < 10){hoursWorked = "0"+hoursWorked} if (minutesWorked < 10){minutesWorked = "0"+minutesWorked} nForm.timeWorked.value = hoursWorked+":"+minutesWorked; } </script> </head> <body> <div align="center"> <h1> <script src='scripts/gen_validatorv5.js' type='text/javascript'></script> <script src='scripts/sfm_moveable_popup.js' type='text/javascript'></script> <style type='text/css'> .error_strings { font-family:Verdana; font-size:10px; color:#660000; } .sfm_float_error_box { position:absolute; z-index:999; cursor:default; font-family:Verdana; font-size:10px; color:#660000; background-color:#ffff66; border-style:solid; border-width:1px; border-color:#660000; } .sfm_float_box_td { padding:3px; cursor:default; font-family:Verdana; font-size:10px; color:#660000; background-color:#ffff66; } .sfm_close_box { font-family:Verdana; font-size:10px; font-weight:bold; color:#ffffff; background-color:#660000; border-width:0px; text-align:center; } .sfm_cr_box { font-family:Verdana; font-size:10px; color:#888888; border-style:solid; border-width:0px; border-color:#660000; } .sfm_cr_box a { color:#888888; } </style> Masquerade Timesheet Entry</h1> </div> <div id='timeSheet_errorloc' class='error_strings' style=''></div> <form name='timeSheet'> <table width="833" height="244" border="1" align="center"> <tr> <td width="266"><p align="left">Monday :</p> Clock In: <label> <input name="inHr" type="text" id="inHr" size="10" maxlength="2"> </label>   <label> <input name="inMin" type="text" id="inMin" size="10" maxlength="2"> </label> <br> Lunch Out: <label> <input name="lunchOutHr" type="text" id="lunchOutHr" size="10" maxlength="2"> </label>   <label></label> <input name="lunchOutMin" type="text" id="lunchOutMin" size="10" maxlength="2"> <br> Lunch In: <label> <input name="lunchInHr" type="text" id="lunchInHr" size="10" maxlength="2"> </label>   <label> <input name="lunchInMin" type="text" id="lunchInMin" size="10" maxlength="2"> </label> <br> Clock Out: <label> <input name="outHr" type="text" id="outHr" size="10" maxlength="2"> </label>   <label> <input name="outMin" type="text" id="outMin" size="10" maxlength="2"> </label> <p>Time Worked: <input type='text' name='timeWorked' size='5' readonly> </p></td> <td width="269"><p>Tuesday:</p> <p>Clock In: <label> <input name="inHr2" type="text" id="inHr2" size="10" maxlength="2"> </label>   <label> <input name="inMin2" type="text" id="inMin2" size="10" maxlength="2"> </label> <br> Lunch Out: <label> <input name="lunchOutHr2" type="text" id="lunchOutHr2" size="10" maxlength="2"> </label>   <label></label> <input name="lunchOutMin2" type="text" id="lunchOutMin2" size="10" maxlength="2"> <br> Lunch In: <label> <input name="lunchInHr2" type="text" id="lunchInHr2" size="10" maxlength="2"> </label>   <label> <input name="lunchInMin2" type="text" id="lunchInMin2" size="10" maxlength="2"> </label> <br> Clock Out: <label> <input name="outHr2" type="text" id="outHr2" size="10" maxlength="2"> </label>   <label> <input name="outMin2" type="text" id="outMin2" size="10" maxlength="2"> </label> </p> <p>Time Worked: <input type='text' name='timeWorked2' size='5' readonly> </p></td> <td width="276"><p>Wednesday:</p> <p>Clock In: <label> <input name="inHr3" type="text" id="inHr3" size="10" maxlength="2"> </label>   <label> <input name="inMin3" type="text" id="inMin3" size="10" maxlength="2"> </label> <br> Lunch Out: <label> <input name="lunchOutHr3" type="text" id="lunchOutHr3" size="10" maxlength="2"> </label>   <label></label> <input name="lunchOutMin3" type="text" id="lunchOutMin3" size="10" maxlength="2"> <br> Lunch In: <label> <input name="lunchInHr3" type="text" id="lunchInHr3" size="10" maxlength="2"> </label>   <label> <input name="lunchInMin3" type="text" id="lunchInMin3" size="10" maxlength="2"> </label> <br> Clock Out: <label> <input name="outHr3" type="text" id="outHr3" size="10" maxlength="2"> </label>   <label> <input name="outMin3" type="text" id="outMin3" size="10" maxlength="2"> </label> </p> <p>Time Worked: <input type='text' name='timeWorked3' size='5' readonly> </p></td> </tr> <tr> <td><p>Thursday:</p> <p>Clock In: <label> <input name="inHr4" type="text" id="inHr4" size="10" maxlength="2"> </label>   <label> <input name="inMin4" type="text" id="inMin4" size="10" maxlength="2"> </label> <br> Lunch Out: <label> <input name="lunchOutHr4" type="text" id="lunchOutHr4" size="10" maxlength="2"> </label>   <label></label> <input name="lunchOutMin4" type="text" id="lunchOutMin4" size="10" maxlength="2"> <br> Lunch In: <label> <input name="lunchInHr4" type="text" id="lunchInHr4" size="10" maxlength="2"> </label>   <label> <input name="lunchInMin4" type="text" id="lunchInMin4" size="10" maxlength="2"> </label> <br> Clock Out: <label> <input name="outHr4" type="text" id="outHr4" size="10" maxlength="2"> </label>   <label> <input name="outMin4" type="text" id="outMin4" size="10" maxlength="2"> </label> </p> <p>Time Worked: <input type='text' name='timeWorked4' size='5' readonly> </p></td> <td><p>Friday:</p> <p>Clock In: <label> <input name="inHr5" type="text" id="inHr5" size="10" maxlength="2"> </label>   <label> <input name="inMin5" type="text" id="inMin5" size="10" maxlength="2"> </label> <br> Lunch Out: <label> <input name="lunchOutHr5" type="text" id="lunchOutHr5" size="10" maxlength="2"> </label>   <label></label> <input name="lunchOutMin5" type="text" id="lunchOutMin5" size="10" maxlength="2"> <br> Lunch In: <label> <input name="lunchInHr5" type="text" id="lunchInHr5" size="10" maxlength="2"> </label>   <label> <input name="lunchInMin5" type="text" id="lunchInMin5" size="10" maxlength="2"> </label> <br> Clock Out: <label> <input name="outHr5" type="text" id="outHr5" size="10" maxlength="2"> </label>   <label> <input name="outMin5" type="text" id="outMin5" size="10" maxlength="2"> </label> </p> <p>Time Worked: <input type='text' name='timeWorked5' size='5' readonly> </p></td> <td><div align="left"> <p> <input type='button' value="Calculate" onClick="calc(this.form)"> <input type="button" name="reset_form" value="Clear Forms" onClick="this.form.reset();"> </p> <p>Total Time Worked: <input type="text" name="totalhr" id="totalhr"> </p> <label></label> </div></td> </tr> </table> <p align="left"> </P> <p align="left"> </P> <p align="left"> </P> <p align="left"> </P> <p><br> <br> <br> <br> </p> </form ><p> </p> <p> </p> </body> </html> <script type="text/javascript"> var myString = "zero one two three four"; var mySplitResult = myString.split(" "); for(i = 0; i < mySplitResult.length; i++){ document.write("<br /> Element " + i + " = " + mySplitResult[i]); } </script> "split" function splits the string whenever it encounters "space". But please explain me how the strings are stored in "mySplitResult". And can we use Arrays for this program? If so, can you code it. Thanks in advance! Im trying to write a program that determines if an array is Ragged or not. I'm fairly new to writing programs in javascript and need a little help with this program. So far I have the following and need to write the program aspect for it. Thanks for taking a look for me. Code: document.writenln("Ragged or not<br />") if (raggedOr(a)) document.writenln("Array is Ragged"); else document.writenln("Array is not Ragged"); raggedOr was going to be the name of the function. Hello people CF, I need some help with this Javascipt program that im trying to make. Ill provide you with the algorithm i have made and the javascript code. I only know basic javascripting and i had a lot of help with this. I need help getting the javascript code for comparing last date modified, renaming the copied file with last date modified, also i can get it to copy 1 file, but i need it to loop through all the files in the given folder. Algorithm Code: // get source and destination folder path // check if folder exists // if source folder exists, continue with the process, otherwise display an error message // if destination folder exists, proceed with transferring the files // get the file collections in the source folder // loop through each file to check if the file has been modified // if the file exists, check file attributes to the source file; 32 means file has changed // if file has changed, // compare the last date modified of the source and destination file // if the source last date modified is greater than the destination last date modified then // rename the destination file by appending the last date modified // to its file name and then transfer the lastest file from the source folder // otherwise, no need to copy the file and move to the next file // otherwise, do nothing and move on to the next file // otherwise, create a folder first before proceeding with transferring the files I had a lot of help with this Code: <HTML> <HEAD> <TITLE>FileSystem Object Demo</TITLE> <SCRIPT> Language = "JavaScript"> <!--hide from old browsers function checkExistingFolder(folder) { var FS = new ActiveXObject("Scripting.FileSystemObject"); return FS.FolderExists(folder); } function createFolder(folder) { var FS = new ActiveXObject("Scripting.FileSystemObject"); FS.createFolder(folder); document.write ("<BR>New folder created."); } function copyFile(source, dest) { var FS = new ActiveXObject("Scripting.FileSystemObject"); FS.copyFile(source + "\\Test.txt", dest + "\\Test.txt"); document.write ("<BR>File Copied."); } function runProgram () { var from = document.getElementById('from').value; var to = document.getElementById('to').value; var isExist = checkExistingFolder(to); alert(isExist); if(isExist) document.write("Folder Exists, checking last date modified........"); else { document.write("Folder doesn't exist."); createFolder(to); } copyFile(from, to); } // --> </SCRIPT> </HEAD> <BODY background="1330843076080.jpg"> <CENTER> <H1>FileSystem Object Demo</H1> FROM: <input type="text" id="from" value=""/> TO: <input type="text" id="to" value="d:\\test"/> <input type="button" onClick="runProgram()" value="Transfer Files"/> <SCRIPT LANGUAGE = "JavaScript"> <!--hide from old browsers // --> </SCRIPT> </CENTER> </BODY> </HTML> Im writing this code for a gas station program. I have been writing and improving my code for about 3 weeks now and its quite long. I have about classes , customer class, office class and a gas pumps classes. I need help on how to get started on finding the total output at the end of the day. Conceptually i know what i have to do but I don't know where to begin writing the code. I think each time there is a new customer i should add the amount of fuel purchased to a new total fuel purchases variable in the gas pump class. If any one could give me some advice or tips on my theory it would be great ! Should I create a method or can i be done without one. Code: import java.util.Random; import java.util.Scanner; public class Customer { private String carTag; private double gasPurchased; private int gasType; public Customer () { Random gen = new Random ( ); carTag = ""; for (int i = 1; i <= 6; i++) { //a random number between 48 and 90 int code = gen.nextInt (43)+ 48; if ((code <= 64) && (code >= 58)) { i--; continue; } carTag += ((char)(code)); } System.out.println ("a car arrives; tag number:" + carTag); } public int getGasType () { Scanner inputDevice = new Scanner (System.in); //1:regular, 2:plus, 3:premium System.out.println ("enter type of gas to buy " + "(1:regular, 2:plus, 3:premium): "); gasType = inputDevice.nextInt (); return gasType; } public double getGasPurchased () { Random gen = new Random (); gasPurchased = gen.nextDouble ()* 50; return gasPurchased; } public String getCarTag () { return carTag; } Code: import java.util.Random; public class Office { public static void main (String [ ] args) { double regularTank = 1000; double plusTank = 1000; double primiumTank = 1000; GasPump pump1 = new GasPump ( ); GasPump2 pump2 = new GasPump2 ( ); Random gen = new Random (); //asuumint gas tanks always have gas, will upgrade later do { int whatHappens = gen.nextInt (100); if (whatHappens == 5) { System.out.println ("gas station closed"); break; } else if ((whatHappens % 10) == 0) { if (pump1.pumpAvailable ()) pump1.customerArrival (); else System.out.println ("a new customer arrives at pump 1, but is turned away, gas pump is busy"); } else { if (pump1.pumpAvailable ()) System.out.println ("no customer; waiting........."); } if (!pump1.pumpAvailable()) { if (pump1.updateClock () == 0) pump1.saleComplete (); } } while (true); do system.exit () Code: public class GasPump { final private double REGULAR_PRICE = 3.15; final private double PLUS_PRICE = 3.5; final private double PREMIUM_PRICE = 4.5; final private double HOSE_FLOW_RATE = 0.85; private double totalPayment; private Customer who; private int timeLeftToFinish; private int gasType; private double gasPurchased; private String carTag; public GasPump () { who = null; totalPayment = 0; timeLeftToFinish = 0; } public void customerArrival () { who = new Customer (); System.out.println ("welcome to jack's gas station PUMP 1 "); gasType = who.getGasType (); gasPurchased = who.getGasPurchased (); timeLeftToFinish = (int)(gasPurchased/HOSE_FLOW_RATE); System.out.println (timeLeftToFinish + " total time units needed for this transaction..."); carTag = who.getCarTag (); } private void printReceipt ( ) { System.out.println ("****Sale Receipt"); switch (gasType) { case 1: System.out.println ("regular gas"); break; case 2: System.out.println ("plus gas"); break; case 3: System.out.println ("premium gas"); break; } System.out.println ("gas amount: " + gasPurchased + "\ntotal payment" + totalPayment + "\nthank you"); System.out.println("Pump has " + regularTank()); } private void resetPump ( ) { who = null; totalPayment = 0; timeLeftToFinish = 0; } public int updateClock () { timeLeftToFinish--; System.out.println (timeLeftToFinish + " time units left to finish "); return timeLeftToFinish; } public void saleComplete ( ) { switch (gasType) { case 1: totalPayment = REGULAR_PRICE * gasPurchased; break; case 2: totalPayment = PLUS_PRICE * gasPurchased; break; case 3: totalPayment = PREMIUM_PRICE * gasPurchased; break; } printReceipt ( ); resetPump ( ); } public boolean pumpAvailable () { return (who == null); } } Basically i have an image of a ball that i am trying to make bounce from top to bottom so far it is just going to the bottom and stopping plz help thanks <head> <title></title> </head> <body> <center> <input type="button" value="Click" onClick="moveDown()"/> </center> <img id="Ball" src="ball.jpg" style="position:absolute; top:100px; left:100px;"/> <script language="JavaScript"> var Image = document.getElementById("Ball"); var Position = 100; var direction = 1; function moveDown() { if(direction > 0) { Image.style.top = parseInt(Image.style.top) + 20+'px'; } if(parseInt(Image.style.top)> 100 || direction > 1 ) direction = 1 if(parseInt(Image.style.top)> 500 || direction < 1 ) { direction = -1 Image.style.top = parseInt(Image.style.top) - 20+'px'; } } setInterval ("moveDown()", 50 ); </script> </body> </html> I have an homework for a web development class. I wrote a program that would be displayed on a webpage that returns the users zodiac sign. It was working just fine until i made small mistake somewhere but i just can't find it. If anyone could help I would appreciate it, I imagine it would be a very easy job for anyone familiar with javascript. [CODE] function signs() { var date=document.zodiac.date.value; var month=document.zodiac.month.selectedIndex; var fortune= new Array() fortune[0]="There is a true and sincere friendship between you and your friends. " fortune[1]="You find beauty in ordinary things, do not lose this ability. " fortune[2]="Ideas are like children; there are none so wonderful as your own. " fortune[3]="It takes more than good memory to have good memories. " fortune[4]="A thrilling time is in your immediate future. " fortune[5]="Your blessing is no more than being safe and sound for the whole lifetime. " if (document.zodiac.month.value == 1 && document.zodiac.date.value >=20 || document.zodiac.month.value == 2 && document.zodiac.date.value <=18) {document.zodiac.sign.value = "Aquarius";} if (document.zodiac.month.value == 1 && document.zodiac.date.value > 31) {document.zodiac.sign.value = "Invalid Date";} if (document.zodiac.month.value == 2 && document.zodiac.date.value >=19 || document.zodiac.month.value == 3 && document.zodiac.date.value <=20) {document.zodiac.sign.value = "Pisces";} if (document.zodiac.month.value == 2 && document.zodiac.date.value > 29) {document.zodiac.sign.value = "Invalid Date?";} if (document.zodiac.month.value == 3 && document.zodiac.date.value >=21 || document.zodiac.month.value == 4 && document.zodiac.date.value <=19) {document.zodiac.sign.value = "Aries";} if (document.zodiac.month.value == 3 && document.zodiac.date.value > 31) {document.zodiac.sign.value = "Invalid Date";} if (document.zodiac.month.value == 4 && document.zodiac.date.value >=20 || document.zodiac.month.value == 5 && document.zodiac.date.value <=20) {document.zodiac.sign.value = "Taurus";} if (document.zodiac.month.value == 4 && document.zodiac.date.value > 30) {document.zodiac.sign.value = "Invalid Date";} if (document.zodiac.month.value == 5 && document.zodiac.date.value >=21 || document.zodiac.month.value == 6 && document.zodiac.date.value <=21) {document.zodiac.sign.value = "Gemini";} if (document.zodiac.month.value == 5 && document.zodiac.date.value > 31) {document.zodiac.sign.value = "Invalid Date";} if (document.zodiac.month.value == 6 && document.zodiac.date.value >=22 || document.zodiac.month.value == 7 && document.zodiac.date.value <=22) {document.zodiac.sign.value = "Cancer";} if (document.zodiac.month.value == 6 && document.zodiac.date.value > 30) {document.zodiac.sign.value = "Invalid Date";} if (document.zodiac.month.value == 7 && document.zodiac.date.value >=23 || document.zodiac.month.value == 8 && document.zodiac.date.value <=22) {document.zodiac.sign.value = "Leo";} if (document.zodiac.month.value == 7 && document.zodiac.date.value > 31) {document.zodiac.sign.value = "Invalid Date";} if (document.zodiac.month.value == 8 && document.zodiac.date.value >=23 || document.zodiac.month.value == 9 && document.zodiac.date.value <=22) {document.zodiac.sign.value = "Virgo";} if (document.zodiac.month.value == 8 && document.zodiac.date.value > 31) {document.zodiac.sign.value = "Invalid Date";} if (document.zodiac.month.value == 9 && document.zodiac.date.value >=23 || document.zodiac.month.value == 10 && document.zodiac.date.value <=22) {document.zodiac..sign.value = "Libra";} if (document.zodiac.month.value == 9 && document.zodiac.date.value > 30) {document.zodiac.sign.value = "Invalid Date";} if (document.zodiac.month.value == 10 && document.zodiac.date.value >=23 || document.zodiac.month.value == 11 && document.zodiac.date.value <=21) {document.zodiac.sign.value = "Scorpio";} if (document.zodiac.month.value == 10 && document.zodiac.date.value > 31) {document.zodiac.sign.value = "Invalid Date";} if (document.zodiac.month.value == 11 && document.zodiac.date.value >=22 || document.zodiac.month.value == 12 && document.zodiac.date.value <=21) {document.zodiac.sign.value = "Sagittarius";} if (document.zodiac.month.value == 11 && document.zodiac.date.value > 30) {document.zodiac.sign.value = "Invalid Date";} if (document.zodiac.month.value == 12 && document.zodiac.date.value >=22 || document.zodiac.month.value == 1 && document.zodiac.date.value <=19) {document.zodiac.sign.value = "Capricorn";} if (document.zodiac.month.value == 12 && document.zodiac.date.value > 31) {document.zodiac.sign.value = "Invalid Date";} document.getElementById("image").src=document.zodiac.sign.value+".jpg" var randomFortune= Math.floor(Math.random() * 5) document.zodiac.fortunebox.value=fortune[randomFortune] document.getElementById('body').style.backgroundColor='#99FFCC' document.getElementById('body').style.backgroundColor='#99FFCC' document.tags.H1.color = '#99FFCC' } [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> <div style="background-color:#000000; height:60px;" > <h1 align="center"> What Zodiac Sign Are You? </h1> </div> <title>Horoscope Fortune Teller</title> <LINK REL=StyleSheet HREF="horoscope.css" TYPE="text/css" MEDIA=screen> <script type="text/javascript" src="Horoscope.js"> </script> </head> <body id=body> <br> <br> <table border=10px; align="center", height="250px"> <form name="zodiac"> <tr><td>Please select your day and month of birth to get started:</td></tr> <br> <br> <tr> <td>Choose month from the list:</td> <td> <select name="month"> <option value="1">January</option> <option value="2">February</option> <option value="3">March</option> <option value="4">April</option> <option value="5">May</option> <option value="6">June</option> <option value="7">July</option> <option value="8">August</option> <option value="9">September</option> <option value="10">October</option> <option value="11">November</option> <option value="12">December</option> </select> </td> </tr> <tr> <td>Enter day of birth:</td> <td><input type="text" name="date" value="Day" onClick=value=""></td> </tr> <tr> <td>Your Zodiac Sign is:</td><td><input type="text" name="sign" value="Zodiac Sign"></td> </tr> <tr> <td><input type="button" value="Click to find your sign" onClick="signs()"></td> <tr><td><img src="" id="image" alt="" /></td><td align="center"><input type="text" name="fortunebox" value="" size="80"></td></tr> </tr> </table> </form> <br> <br> <br> <br> <div style="background-color:#000000; height:60px;"></div> </body> </html> |