Featured Worklog

Price Search



PC Apex Sponsor


PC Apex Sponsors



PC Apex RSS Feeds

RSS Feed for PC Apex Reviews & ArticlesRSS Feed for PC Apex PC Modding WorklogsRSS Feed for the PC Apex Daily DisturbanceRSS Feed for the latest PC Apex Site NewsRSS Feed for PC Apex Affiliate and Web NewsRSS Feed for PC Apex Deals and Steals

Go Back   Apex Community Forums // Other Forums // Miscellaneous Stuff // Anything Goes

Anything Goes Just like it says... anything goes.

Reply
 
LinkBack Thread Tools Display Modes
Old 24-January-03, 06:06 PM   #1 (permalink)
Apex Techie Lite
Default Plz help if you know JavaScript

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
Lazy8s is offline     Reply With Quote
Old 24-January-03, 06:07 PM   #2 (permalink)
Apex Techie Lite
Default




there's the code...it didn't work on the last page...
Lazy8s is offline     Reply With Quote
Old 24-January-03, 06:08 PM   #3 (permalink)
Apex Techie Lite
Default

Crap, the code won't show. Just go to the link, exit the program, go to View, and then source...
Lazy8s is offline     Reply With Quote
Old 24-January-03, 06:25 PM   #4 (permalink)
Apex Techie II
Soulless's Avatar
Default

I would have used .5 instead of (1/2) sometimes I have seen fractions mess up a program....

And I don't believe you can call a fuctions variable outside the function...
Though I must admit it have been a little while since I porgrammed anything....

Soulless
Soulless is offline     Reply With Quote
Old 24-January-03, 06:27 PM   #5 (permalink)
Apex Elite Tech
Sk8forMaple's Avatar
Default

I tried changing the 1/2 to .5 soulless... it didn't work
Sk8forMaple is offline     Reply With Quote
Old 24-January-03, 06:29 PM   #6 (permalink)
Apex Techie Lite
Default

thank you, I originally had it as a decimal and thought maybe that was screwing it up, it seems to not work either way. I will try calling the functionspecific variables inside the functions and keep you updated, thank you
Lazy8s is offline     Reply With Quote
Old 24-January-03, 06:36 PM   #7 (permalink)
Apex Techie Lite
Default

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...
Lazy8s is offline     Reply With Quote
Old 24-January-03, 06:53 PM   #8 (permalink)
'Da Doctor of Funk
FunkyFresh's Avatar
Default

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..
FunkyFresh is offline     Reply With Quote
Old 24-January-03, 06:56 PM   #9 (permalink)
Apex Techie Lite
Default

awesome, I had it something like that earlier (but not calling the variables, thank you, I will try that when I can, g2g to class now
Lazy8s is offline     Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On


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


All times are GMT -5. The time now is 08:04 PM.


Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0
Copyright PCApex.com, GameApex.com, ForumApex.com 2001 - 2008
Advertisements

Page generated in 0.20556 seconds with 9 queries