| |||||||
| Anything Goes Just like it says... anything goes. |
![]() |
| | LinkBack | Thread Tools | Display Modes |
| | #1 (permalink) | |
| Apex Techie Lite | I am SO frustrated, I am learning JavaScript for class and our teacher gave us this assignment: The purpose of this program is to allow the user to input four numbers: test average, program average, final exam grade, and attendance grade. The program then calculates the final average of the student based on the weights each part of the grade counts for this class. Your program must comply with the following specifications: Prompt the user for a student name Prompt the user for a test average Prompt the user for a program average Prompt the user for a final exam score Prompt the user for an attendance grade Give each of the four values an appropriate weight, as described in the class syllabus, and calculate the average for the student. Print out the average for the student using a JavaScript alert. Prompt the user for another student name. Repeat until the user enters NONE as the student's name. When this happens the program should terminate. The program must be named average.html. It must contain html code with embedded JavaScript code. It must be a structured program accessible through http://www.valdosta.edu/~yourUserNam.../average.html. In order to get a 100 on this program, the function of calculating the average must be in a module which is called by the main program. ...okay, so I have it in the right place and all, that's not the problem, the problem is that my program skips right over my function. It does EVERYTHING in the loop it's supposed to and correctly defines all the variables in the loop, but skips the function almost like it doesn't exist. I have tried countless online tutorials and just don't understand JavaScript enough to fix it. Here's the link: www.valdosta.edu/~wrconkli/CS1010/average.html and here's my code: w ...any help would be GREATLY appreciated. Thank you in advance | |
| | | |
| | #7 (permalink) | |
| Apex Techie Lite | well, I changed it to this: var studentName //the student in question's name var testAvg //their average for all their tests var programAvg //their average for programs var finalExam //their grade on the final exam //all vars abive here are user defined var finalGrade studentName = prompt("Please enter the name of a student or type NONE to exit.","") //priming read; prompts user to input the student's grade while (studentName != "NONE") //loop that prompts user for all of the user defined variables { testAvg = prompt("Enter " + studentName + "'s test average.","") programAvg = prompt("Enter " + studentName + "'s program average.","") finalExam = prompt("Enter " + studentName + "'s final exam grade.","") attendanceGrade = prompt("Enter " + studentName + "'s attendance grade.","") function calculateGrade() { var weightedTestAvg var weightedProgramAvg var weightedFinalExam var weightedAttendanceGrade var finalGrade weightedTestAvg = testAvg * (1/2) weightedProgramAvg = programAvg * .25 weightedFinalExam = finalExam * .2 weightedAttendanceGrade = attendanceGrade * .05 finalGrade = weightedTestAvg + weightedProgramAvg + weightedFinalExam + weightedAttendanceGrade } alert(studentName + " made a " + finalGrade + " in CS1010.") alert("weightedTestAvg = " + weightedTestAvg) studentName = prompt("Please enter the name of a student or type NONE to exit.","") } and it still doesn't work. Actually, now it stops right before the function. None of the loop from the function down works now..hmm... | |
| | | |
| | #8 (permalink) | |
| You have to define the function outside the loop, then call it from inside the loop. Something like the following (I haven't checked the actual code to make sure it works, but this is closer to the form it should take): EDIT: I changed the code around a bit; you'll have to check the math to see if it's coming out how you want, but at least this'll run now: Code: var studentName; //the student in question's name
var testAvg; //their average for all their tests
var programAvg; //their average for programs
var finalExam; //their grade on the final exam
var weightedTestAvg;
//all vars abive here are user defined
var finalGrade;
studentName = prompt("Please enter the name of a student or type NONE to exit.","");
//priming read; prompts user to input the student's grade
while (studentName != "NONE")
//loop that prompts user for all of the user defined variables
{
testAvg = prompt("Enter " + studentName + "'s test average.","");
programAvg = prompt("Enter " + studentName + "'s program average.","");
finalExam = prompt("Enter " + studentName + "'s final exam grade.","");
attendanceGrade = prompt("Enter " + studentName + "'s attendance grade.","");
calculateGrade();
alert(studentName + " made a " + finalGrade + " in CS1010.");
alert("weightedTestAvg = " + weightedTestAvg);
studentName = prompt("Please enter the name of a student or type NONE to exit.","");
}
function calculateGrade()
{
var weightedProgramAvg;
var weightedFinalExam;
var weightedAttendanceGrade;
weightedTestAvg = testAvg * (1/2);
weightedProgramAvg = programAvg * .25;
weightedFinalExam = finalExam * .2;
weightedAttendanceGrade = attendanceGrade * .05;
finalGrade = weightedTestAvg + weightedProgramAvg + weightedFinalExam + weightedAttendanceGrade;
}
Last edited by FunkyFresh; 24-January-03 at 07:07 PM.. | ||
| | | |
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Javascript inserted into table - problems | nev_payne | Coding / Scripting / Programming | 0 | 26-June-06 04:18 AM |
| Web Trick: Images Rollovers without Javascript | FunkyFresh | Coding / Scripting / Programming | 5 | 09-August-05 05:00 PM |
| Slashdot // JavaScript Inventor Speaks Out | Gizmo | Slashdot RSS | 0 | 16-June-05 03:21 PM |
| Any JavaScript pimps in here?? | NapalmStixToKidz | Coding / Scripting / Programming | 10 | 03-August-04 06:15 PM |
| JavaScript and Fifrebird | Spc. Forces Bob | Other PC Problem / Help | 0 | 05-January-04 04:18 PM |