437,605 Members | 2,147 Online Need help? Post your question and get tips & solutions from a community of 437,605 IT Pros & Developers. It's quick & easy.

# Learning Javascript

 P: 6 Hi, I am learning Java, and working on a program that reads the grades of homework, midterm1, midterm2, and final, and calculates the overall average and final letter grade. Assume that the maximum point of the homework is 150, and those of midterm1, midterm2 and final are 100. The overall average is to be calculated as follows: homework: 40% midterm1: 15% midterm2: 20% final: 25% And am suppose to use a function that calculates the overall average, and another function that calculates the final grade. You are also to use an extended if or a switch statement in the program. I have this so far; [HTML]vr hw,mt1,mt2,fin,avg; hw= parseFloat(prompt("Enter Homework Grade.")); mt1= parseFloat(prompt("Enter Midterm 1 Grade.")); mt2= parseFloat(prompt("Enter Midterm 2 Grade.")); fin= parseFloat(prompt("Enter Final Grade.")); if(hw>150) document.write("Homework points are to large.
"); if(hw<0) document.write("Homework points are to small.
"); if(mt1>100) document.write("Midterm 1 points are to large.
"); if(mt1<0) document.write("Midterm 1 points are to small.
"); if(mt2>100) document.write("Midterm 2 points are to large.
"); if(mt2<0) document.write("Midterm 2 points are to small.
"); if (fin>100) document.write("Final points are to large.
"); if (fin<0) document.write("Final points are to small.
"); hw=.40*150; mt1=.15*100; mt2=.20*100; fin=.25*100; avg=(hw+mt1+mt2+fin); var grade; if (avg<=50) document.write("Grade is an F."); else if(avg<=60) document.write("Grade is an D."); else if(avg<=70) document.write("Grade is an C."); else if(avg<=80) document.write("Grade is an B."); else if (avg<=90) document.write("Grade is an A."); [/HTML] What am I not doing correctly? Sep 30 '07 #1
9 Replies

 Expert 10K+ P: 11,448 What am I not doing correctly? 1) posting in the wrong section; 2) mistaking Java for Javascript. I'll move your question to the Javascript forum section; see the blue menu bar near the top of this page: select 'Forums' and 'Javascript/Ajax'. kind regards, Jos Sep 30 '07 #2

 P: 6 1) posting in the wrong section; 2) mistaking Java for Javascript. I'll move your question to the Javascript forum section; see the blue menu bar near the top of this page: select 'Forums' and 'Javascript/Ajax'. kind regards, Jos Thanks, I hope with my question in the correct area now, I will get the help I need to finish my assignment! Sep 30 '07 #3

 P: 6 Hi, I am learning Java, and working on a program that reads the grades of homework, midterm1, midterm2, and final, and calculates the overall average and final letter grade. Assume that the maximum point of the homework is 150, and those of midterm1, midterm2 and final are 100. The overall average is to be calculated as follows: homework: 40% midterm1: 15% midterm2: 20% final: 25% And am suppose to use a function that calculates the overall average, and another function that calculates the final grade. You are also to use an extended if or a switch statement in the program. I have this so far; [HTML]vr hw,mt1,mt2,fin,avg; hw= parseFloat(prompt("Enter Homework Grade.")); mt1= parseFloat(prompt("Enter Midterm 1 Grade.")); mt2= parseFloat(prompt("Enter Midterm 2 Grade.")); fin= parseFloat(prompt("Enter Final Grade.")); if(hw>150) document.write("Homework points are to large.
"); if(hw<0) document.write("Homework points are to small.
"); if(mt1>100) document.write("Midterm 1 points are to large.
"); if(mt1<0) document.write("Midterm 1 points are to small.
"); if(mt2>100) document.write("Midterm 2 points are to large.
"); if(mt2<0) document.write("Midterm 2 points are to small.
"); if (fin>100) document.write("Final points are to large.
"); if (fin<0) document.write("Final points are to small.
"); hw=.40*150; mt1=.15*100; mt2=.20*100; fin=.25*100; avg=(hw+mt1+mt2+fin); var grade; if (avg<=50) document.write("Grade is an F."); else if(avg<=60) document.write("Grade is an D."); else if(avg<=70) document.write("Grade is an C."); else if(avg<=80) document.write("Grade is an B."); else if (avg<=90) document.write("Grade is an A."); [/HTML] What am I not doing correctly? Allows me to enter points in browser, but is not calculating grades????? Sep 30 '07 #4

 Expert 5K+ P: 5,821 Heya, Senso. Welcome to TSDN! In these lines: Expand|Select|Wrap|Line Numbers hw=.40*150; mt1=.15*100; mt2=.20*100; fin=.25*100;   Did you mean to use *= instead of = ? Sep 30 '07 #5

 P: 6 Heya, Senso. Welcome to TSDN! In these lines: Expand|Select|Wrap|Line Numbers hw=.40*=150; mt1=.15*=100; mt2=.20*=100; fin=.25*=100;   Did you mean to use *= instead of = ? Now, I am really lost. This program needs to be set up to calculated weighted averages of hw, mt1, mt2 and fin. So far, all I can get it to do is allow me to enter the points for hw, mt1, mt2 and final in browser. I am guessing once these total are entered the percentages need to be used and a grade will be calculated based on avg???? It needs to print grade. which it is not doing? Sep 30 '07 #6

 Expert 5K+ P: 5,821 Heya, Senso. I meant this: Expand|Select|Wrap|Line Numbers hw *= 0.40 * 150;   Sep 30 '07 #7

 P: 6 Heya, Senso. I meant this: Expand|Select|Wrap|Line Numbers hw *= 0.40 * 150;   Really having a time,. can't believe how hard this is. Still not working for me! Sep 30 '07 #8

 P: 6 Still having a really tough time, program is not doing what it should....Help! Sep 30 '07 #9

 Expert Mod 15k+ P: 16,027 Still having a really tough time, program is not doing what it should....Help! So what is it doing instead? Oct 1 '07 #10 