473,387 Members | 1,771 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Learning Javascript

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.<BR>");
if(hw<0)
document.write("Homework points are to small.<BR>");
if(mt1>100)
document.write("Midterm 1 points are to large.<BR>");
if(mt1<0)
document.write("Midterm 1 points are to small.<BR>");
if(mt2>100)
document.write("Midterm 2 points are to large.<BR>");
if(mt2<0)
document.write("Midterm 2 points are to small.<BR>");
if (fin>100)
document.write("Final points are to large.<BR>");
if (fin<0)
document.write("Final points are to small.<BR>");

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.");

</SCRIPT>
</HEAD>
<BODY>

</BODY>
</HTML>[/HTML]

What am I not doing correctly?
Sep 30 '07 #1
9 1989
JosAH
11,448 Expert 8TB
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
senso
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
senso
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.<BR>");
if(hw<0)
document.write("Homework points are to small.<BR>");
if(mt1>100)
document.write("Midterm 1 points are to large.<BR>");
if(mt1<0)
document.write("Midterm 1 points are to small.<BR>");
if(mt2>100)
document.write("Midterm 2 points are to large.<BR>");
if(mt2<0)
document.write("Midterm 2 points are to small.<BR>");
if (fin>100)
document.write("Final points are to large.<BR>");
if (fin<0)
document.write("Final points are to small.<BR>");

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.");

</SCRIPT>
</HEAD>
<BODY>

</BODY>
</HTML>[/HTML]

What am I not doing correctly?
Allows me to enter points in browser, but is not calculating grades?????
Sep 30 '07 #4
pbmods
5,821 Expert 4TB
Heya, Senso. Welcome to TSDN!

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

In these lines:
Expand|Select|Wrap|Line Numbers
  1. hw=.40*=150;
  2. mt1=.15*=100;
  3. mt2=.20*=100;
  4. fin=.25*=100;
  5.  
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
pbmods
5,821 Expert 4TB
Heya, Senso.

I meant this:
Expand|Select|Wrap|Line Numbers
  1. hw *= 0.40 * 150;
  2.  
Sep 30 '07 #7
senso
6
Heya, Senso.

I meant this:
Expand|Select|Wrap|Line Numbers
  1. hw *= 0.40 * 150;
  2.  
Really having a time,. can't believe how hard this is. Still not working for me!
Sep 30 '07 #8
senso
6
Still having a really tough time, program is not doing what it should....Help!
Sep 30 '07 #9
acoder
16,027 Expert Mod 8TB
Still having a really tough time, program is not doing what it should....Help!
So what is it doing instead?
Oct 1 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Sean McCourt | last post by:
Hi I am doing a JavaScript course and learning from the recommed book (JavaScript 3rd Edition by Don Gosslin) Below is one of the exercises from the book. I get this error message when I try to...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
2
by: rich | last post by:
I'd like to improve my webdesign knowledge and learn how to write Javascripts. I have built my own website. I have javascripts on my site that I havent written. I download them and edit them where...
6
by: Helpful person | last post by:
I have written my web site using FrontPage and have disvovered that apart from producing code that does not validate it also creates a horrible structure. I have been teaching myself HTML...
10
by: Michael Reach | last post by:
Can anyone suggest a really good course in Javascript that my son can take online, starting right away? It should be for someone without much programming experience, and I mean a real course, that...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.