Jump to content

simple javascript problem


jdeneca

Recommended Posts

I am trying to write a program to display 4 different grades for 4 different courses in Javascript.I have to do this as a new object with three properties (Code, Name, Score) I have created the object but now I have to create a method that will identify grades by >=90 is an A and so on down to a B. I am lost on writing the method function on how to do this. Originally I started out: score.prototype.getScore = function(){return this.scoreHow can I setup the score to be by grade score in percentage?Anyone understand

Link to comment
Share on other sites

Part of it might involve an array that maps numerical grades to alpha grades.If you only need one kind of score object, you might just as well add your methods to the object constructor function. Changing the prototype seems like a duplicated effort.

Link to comment
Share on other sites

Well this is what I have so far and my scores that are just showing in the string are showing as dollar values when they should be integers and I need to concatenate in the final string the grade. This is what I have: <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head> <title>Week 3 Chapter 11</title> </head><body> <script type="text/javascript"> var course = function(code,name,score) { this.code = code; this.name = name; this.score = score; } // use the prototype property to add a methods to the vehicle type // a method to display all properties of a vehicle object course.prototype.toString = function() { return this.code + ' ' + this.name + ', $' + this.score; } // a method to retrieve a vehicle object's price course.prototype.getScore = function() { if this.score >=90 return this } // create a few objects with the constructor as before var Course1 = new course('COP2300','Something Computer Programming',88); var Course2 = new course('CGS1000','Intro to Computer Programming',78); var Course3 = new course('CGS1100','Micro Computers', 67); var Course4 = new course('COP2801','Javascript',100); // now use the new methods document.write('<h4>' + Course1.toString() + '</h4>'); document.write('<h4>' + Course2.toString() + '</h4>'); document.write('<h4>' + Course3.toString() + '</h4>'); document.write('<h4>' + Course4.toString() + '</h4>'); </script> </body></html>

Link to comment
Share on other sites

Oops. I'm a college professor. Helping out with homework creates ethical problems for me. Maybe someone else can help. I will give you a couple hints before I go, however.Hint 1: the more specific your questions are, the more likely you are to get good answers.Hint 2: be willing to experiment over and over again. It's been 30 minutes since my first post. If you haven't rewritten your code at least twice since then, you're not going to get very far.

Link to comment
Share on other sites

Oops. I'm a college professor. Helping out with homework creates ethical problems for me.
I'm not a college professor, and helping out with homework creates ethical problems for me too... and for many other people on the board too... I can only imagine your mental conflict as a three times more of a struggle :) .But still... I'm willing to give more practical hints... but I didn't understood the question really. What is it again? No, don't tell me what's the assignment. Tell me what part of it are you failing to accomplish.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...