JavaScript - Need Help With An Assigment About Grade Average!
Hello, I'm new here and a newbie to the world of java script. I am taking a CIT class and we just moved on to java script which i am having trouble with. My assignment is to calculate the average, number of passed, and number of failed grades according to this list (65, 80, 85, 55, 90, 70, 62, -1) where it terminates at -1 and the passing grade is >=70.
Any help is appreciated! Similar TutorialsHi, I have written a function to compare each character in startString with another nominated character (nomChar). If they are the same this character is written to outputString, in the same position. If they are not the same a character is lifted from the same position in altString and placed in the same position in outputString instead. I hope that's clear! Code as follows: Code: function compareChar(startString, altString, nomChar) { var outputString = ''; outputString.length = startString.length; var nextLetter = ''; for (var count = 0; count < startString.length; count = count + 1) { nextLetter = startString.charAt(count); if (nextLetter == nomChar) { outputString.charAt(count) = nextLetter; } else { outputString.charAt(count) = altString.charAt(count); } } } document.write(compareChar('boston', 'denver' , 'o' ) ); However, the line of code within the if statement Code: outputString.charAt(count) = nextLetter; keeps generating an 'Invalid assigment left hand side' error message. Can anyone see why this is the case? Thanks. i wold like to get this working. when a user enters 4 grades into the text boxes. it would give them the Avg Grade and also what Mark they got, and if they failed one out put the module they most Repeat and if they passed all out put a smiley face.. This is what i have so far.. Code: function compute() { var c = document.getElementById("c").value; var computer = document.getElementById("computer").value; var web = document.getElementById("web").value; var math = document.getElementById("math").value; document.getElementById("cost").value = totalCost = (c * 100 + computer * 100 + web * 100 + math * 100 ) /4; if(cost >=93) alert(" You got an A+") else if((cost >=85)&(grade <93)) alert(" You got an A") else if((cost >=78)&(grade <85)) alert(" You got an B") else if((cost >=60)&(grade <78)) alert(" You got an C") else if((cost >=40)&(grade <60)) alert(" You got an D") else if(cost <40) alert(" You Failed this Module") </script> </head> <body> <form method="get" action="" onsubmit='return formValidator()' > <fieldset id="personalInfo"> <h3> Student Results </h3> <!-- A bordered table for item orders --> <table border = "border"> <!-- First, the column headings --> <tr> <th> Module Name </th> <th> Pass Mark </th> <th> Final Mark </th> </tr> <!-- Now, the table data entries --> <tr> <th> C++ </th> <td> 40 % </td> <td> <input type = "text" id = "c" size ="10" /> </td> </tr> <tr> <th> Computer Systems </th> <td> 40 % </td> <td> <input type = "text" id = "computer" size = "10" /> </td> </tr> <tr> <th> Web Development </th> <td> 40 % </td> <td> <input type = "text" id = "web" size = "10" /></td> </tr> <tr> <th> Maths </th> <td> 40 % </td> <td> <input type = "text" id = "math" size ="10" /> </td> </tr> </table> <!-- Button for precomputation of the total cost --> <p> <input type = "button" value = "Total Grade" onclick = "compute();" /> <input type = "text" size = "5" id = "cost" onfocus = "this.blur();" /> </p> </fieldset> </p> <input type='submit' value='Check Form' /> </form> </body> </html> I have this project i have to complete for class, that i cant figure out. this is what the project says: Prompt the user for the grades of 10 students with one prompt for each grade with the prompting text being: "Enter grade between 1 and 10 for student n:" where n varies from 1 to 10. If the grade input is not between 1 and 10, please prompt again for the grade. Once the user is done, it prints a report telling you the grade of each individual student and the average of the ten grades. The individual student grade should be in different lines with the text "Grade for student n is x". The average should also be in a different line with the text "Average grade is y". The average grade should not be rounded off. my problem is i cant figure out how to write each individual grade (from 1 through 10), and display it on the page. i have this code from a similar project, i tried to ammend it for this code but i always end up ruining it any tips on how to display each grade (1-10)? or how to verify that the user only enters grades between 1 and 10 Code: <html xmlns = "http://www.w3.org/1999/xhtml"> <head> <title>Class Average Program: Sentinel-controlled Repetition</title> <script type = "text/javascript"> <!-- var total; // sum of grades var gradeCounter; // number of grades entered var grade; // grade typed by user (as a string) var gradeValue; // grade value (converted to integer) var average; // average of all grades // Initialization phase total = 0; // clear total gradeCounter = 0; // prepare to loop // Processing phase // prompt for input and read grade from user grade = window.prompt( "Enter Integer Grade, -1 to Quit:", "0" ); // convert grade from a String to an integer gradeValue = parseInt( grade ); while ( gradeValue != -1 ) { // add gradeValue to total total = total + gradeValue; // add 1 to gradeCounter gradeCounter = gradeCounter + 1; // prompt for input and read grade from user grade = window.prompt( "Enter Integer Grade, -1 to Quit:", "0" ); // convert grade from a String to an integer gradeValue = parseInt( grade ); } // end while // Termination phase if ( gradeCounter != 0 ) { average = total / gradeCounter; // display average of exam grades document.writeln( "<h1>Class average is " + average + "</h1>" ); } // end if else document.writeln( "<p>No grades were entered</p>" ); // --> </script> </head> <body> <p>Click Refresh (or Reload) to run the script again</p> </body> </html> So I am making a function that takes numbers and when you enter a letter than it's supposed to skip to the if statement and give the average. The problem is that it doesn't seem to add the number to total on each loop. the first code is what I am working with. I was supposed to take a While loop and turn it into a do-while loop. The second peice of code is the original while loop. } Code: var finding_average = function() { var total = 0, count = 0, number; alert("Enter the numbers to average. Enter any non-number to stop."); do { number = parseInt( prompt("Enter a number") ); total = total + number; count++; } while ( !isNaN(number) ); var average = total / count; if ( isNaN(average) ) { alert("You didn't enter any numbers."); } else { alert("The average is: " + average); } Code: var finding_average = function() { var total = 0, count = 0, number; alert("Enter the numbers to average. Enter any non-number to stop."); number = parseFloat( prompt("Enter a number") ); while ( !isNaN(number) ) { total += number; count++; number = parseFloat( prompt("Enter another number") ); } var average = total / count; if ( isNaN(average) ) { alert("You didn't enter any numbers."); } else { alert("The average is: " + average); } } hi I need to find the average number in javascript. I have been working on it for a while but i am getting no where yes i am new to javascript and to be honest it is doing my blonde headed brain in. can someone please take a look at it and advise me on what i am doing wrong. it is the only bit of javascript that i have to do in the course but it carries a high mark of which i can not afford to lose Any way the question is : "Write code to calculate the average height and write it out in the browser window" Code: <HEAD> <TITLE> average </TITLE> <SCRIPT LANGUAGE = "JavaScript"> //Experimental results of Table 1 stored in arrays. var Height = [15,16,17,18,19]; var Number = [2,1,6,4,2]; //Part (ii). //Write code to declare and initialise new array to represent the third row of the table. var avg = new Array(5) var avg = ["60","80","187","180","114"] ; avg[0] = "60"; avg[1] = "80"; avg[2] = "187"; avg[3] = "180"; avg[4] = "114"; //Part (iv). //Write code to calculate the average height and write it out in the browser window. avg = 0; for (var count = 1; count <= 5; count = count + 1) Array.average = function(){ var avg = 0; for(var a = 0; a < this.length; a++){ avg += this[a]; } return avg / this.length; }; document.write('average height is ' +avg + '<br>'); </SCRIPT> </HEAD> <BODY> </BODY> </HTML> sorry for my ignorance thanks in advance kelly XXXXX I am trying to create a grading calculator which will prompt the user to enter specific data and calculate the final grade. Here is code which I modified from an earlier post from Philip M. Code: <script type = "text/javascript"> var count = 1; var total = 0; var info= new Array(); var numGrades = 2; for (var i = 0; i<numGrades; i++) { var repeat = true; while(repeat) { var ans = parseInt (prompt("Enter grade between 0%-100% for Grade # "+ count,"")); if ((isNaN(ans)) || (ans == null) || (ans < 1) || (ans > 100)) { alert ("You must enter a number between 0 and 100"); } else { repeat = false; count ++; info[i] = ans; total = total + info[i]; } } } var avg = total/info.length; for (var i = 0; i < info.length; i++) { document.write("Grade " + (i+1) + " Marks = " + info[i] + "<br>"); } document.write("<br> Average Mark = " + avg.toFixed(2)) </script> Here is the hard part: I am trying to make it so it will first ask how many grades to be calculated rather than a fixed grade. Then it will ask for grade 1 how many grades to be calculated for grade 1 and there percentage. Example: (alert box) How many overall grades to be calculated? User types 2 (alert box) Grade1 how many quizzes to be calculated? User types 2 (alert box) quiz 1 how much percent is this worth out of 100%? User types 80% (alert box) What grade did you receive? (alert box) quiz2 how much percent is this worth out of 100%? User types 20% (alert box) What grade did you receive? (alert box) Grade2 how many quizzes to be calculated? User types 1 (alert box) quiz 1 how much percent is this worth out of 100%? User would type 100% (alert box) What grade did you get? And then the results should look something like this: Grade 1 you got an 86% Grade 2 you got an 91 Final grade = ….. This is probably just a dumb way of doing this so anyway which will get the same result will be fine. I'm not sure if alert box is the wrong way to go. I need to allow a user to enter 3 values, then display the average between them... I am having some real issues with the average, Thanks! var quiz1 = prompt("What is the score of your first quiz?", "") document.write("Return Value: "+quiz1, '%',("<br />")); var quiz2 = prompt("What is the score of your second quiz?", "") document.write("Return Value: "+quiz2, '%',("<br />")); var quiz3 = prompt("What is the score of your third quiz?", "") document.write("Return Value: "+quiz3,'%',("<br />")); average= ("quiz1"+"quiz2"+"quiz3") /3 document.write(average,("<br />")); helow to every one im new here....i hope im welcome here can i ask how to make this problem? input 20 number and print the average of the numbers....any one can help me please... Hi i need to find the highest average from all of the averages entered in this code, but i have to use an if statement only, no arrays. Could some one help please? Code: // ** Work out average ** // average= readingSum/totalReadings // ** Put average into a category and display everything ** // if(average<5) { catergory1=alert("Location is " + region + "\nNumber of weekly readings taken is " + totalReadings + "\nTotal of readings is" + readingSum + "\nAverage is" + average + "\nLocation is Dry"); } else if(average>=5 && average<20) { catergory2=alert("Location is " + region + "\nNumber of weekly readings taken is " + totalReadings + "\nTotal of readings is" + readingSum + "\nAverage is" + average + "\nLocation is Normal"); } else if(average>20) { catergory3=alert("Location is " + region + "\nNumber of weekly readings taken is " + totalReadings + "\nTotal of readings is" + readingSum + "\nAverage is" + average + "\nLocation is Wet"); } // ** Find Highest average ** // Thanks. Hi, First i don know if im posting at the right place or if you even take request here, feel free to direct me to the right place. What i am looking for is someone to make a simple counter for me. Basically i want that every time i press a certain key on my keyboard it will increase the counter amount and would then divide it by 60 every hour. Actually im looking for it to only show that average and refresh every hour. So it would start at 0 then update after the first hour and so on. (I also need a graphical interface) I have very few knowledge in coding and would very appreciate if someone could do that for me. Thank you ! Reply With Quote 01-10-2015, 11:39 PM #2 Old Pedant View Profile View Forum Posts Supreme Master coder! Join Date Feb 2009 Posts 28,311 Thanks 82 Thanked 4,754 Times in 4,716 Posts I don't think this is something you would do with JavaScript. I think you need a ".exe" (on Windows) program. And that's a lot more complex. The problem is your request to capture a certain key, presumably no matter what window is at the front. Normally, within a given window, you can only capture a key that is intended for that window. I don't think this is a very easy thing to do. Hi all, I am in a non-major class called webprogramming working with javascript and I'm having an issue with a specific code wondering if someone could tell me what's wrong! So I am suppose to compute and return the average of all values in a given array named customerBalance, the array holds the amount of "what customers owe my business" (I dont own a business) and each item in the array holds the "customers balance", i also have to use a for() to process the array and calculate the average and divide by customerBalance length, and finally return the average. Here is my code so far <script> function average() { customerBalance for(i=0,i++) sum(customerBalance) total=sum/5 return average; }; </script> I know that this is COMPLETELY wrong, I am not sure on how i start typing the array, please don't be harsh I would really like to know how to do this. Thank you and have a great day I've now got to form an average of snowfall inputs, taken from looped prompts, however I'm not allowed to use arrays or functions... Almost every example I see uses arrays, such as this one he http://www.codingforums.com/showthread.php?t=4313 Is it possible to not use arrays to form the average? Please describe how to do this in general terms, as was highlighted in that link ^^^ I want to learn, not copy, although one can be derived from the other... What I haveso far, assume all vars have been announced. Code: for (var d=1; d<=numofinputs; d=d+1) { input = prompt("Enter a data input" + d) } Is it possible I'm attempting this in too general a manner? ie, running before I can walk. I've written a program which will prompt for a number of cities, Prompt for the name of the city, then prompt for the number of snowfall readings of that city, and then prompt for each of these individual snowfall readings of that city. From this, it adds up each of the individual snowfall readings of that city, and will calculate an average by dividing this figure [the total snowfall] by the total number of readings for that city. This average is used to then classify the city as "not snowy", "mild", or "blizzard". I'm happy to PM my code to anyone willing to help out, as I realise this is a complex structure to visualise perhaps, but I can't post it publicly. I now have to select the city with the highest average, and name it in an alert output. How is this possible. Note, I'm not allowed to use functions or arrays. Prompts, alerts, if-then-else, for and while loops are all I can use. I've been messing with this code for about a couple of hours, and I did everything down to the wire..yet still I am unable to get it to work. When I input the numbers, and click off to the side nothing appears down at the final textarea of the form which is suppose to show the average. I've tried just about everything, sadly all I have to go by is other example codes, and the very intricate instructions which states I must pass the values to the calcAvg() to the second function of performCalc(), which I did, and then I assigned the var calcResult another value. From there I did the return..and after that I'm rather loss as to what to do next to get this code to work, any tips? 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> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Calculation Average</title> <script type="text/html"> /* <![CDATA[ */ function calcAvg() { var calcResult=document.numbers.number1.value + document.numbers.number2.value +document.numbers.number3.value + document.numbers.number4.value + document.numbers.number5.value } function performCalc() { var calcResult = calcResult / 5 return calcResult; } /* This is what I got so far, as you can see I need plenty of help!*/ </script> </head> <H1> Calculate Average of Numbers</H1> <body> <form action="" name="numbers"> <table> <tr> <td> <tr> <td>Enter the five numbers:<br /> </td></tr> <tr><td> <input type="text" name="number1" size="3" onchange="calcAvg()" text="0" /></td> </tr> <tr> <td> <input type="text" name="number2" size="3" onchange="calcAvg()" text="0" /></td> </tr> <tr> <td> <input type="text" name="number3" size="3" onchange="calcAvg()" text="0" /></td> </tr> <tr> <td> <input type="text" name="number4" size="3" onchange="calcAvg()" text="0" /></td> </tr> <tr> <td> <input type="text" name="number5" size="3" onchange="calcAvg()" text="0" /></td> </tr> </table> </form> <form action="" name="averageResult"> <p> Estimate average: <input type="text" name="average" size="5" style="border-style: none; border-color: inherit; border-width: medium; background-color: Transparent" text="0" /></p> </form> </body> </html> |