...

View Full Version : function result not displayed



priyaa2002
10-04-2010, 06:43 PM
Can anyonle pls explain me why the return function is not returning the result as intended? I appreciate you help


OUTPUT
======

Student : Doe,John
eMail : johndoe@gmail.com
Course ID : COIN-070B.01
--------------------------------
function task() { var title = ["Assignment1", "Assignment2", "Assignment3", "Assignment4", "Assignment5", "Mid Term", "Finals"]; var points = [30, 30, 28, 27, 29, 41, 45]; for (var i = 0; i < points.length; i++) { titlePoints += title[i] + (" : " + points[i] + "\n"); } return titlePoints; }




<head>
<title>Variable - Examples 1</title>
<script type="text/javascript">
function Student(firstName, lastName, email,courseID){
this.firstName = firstName;
this.lastName = lastName;
this.email = email;
this.courseID = courseID;
this.assignments = task;
}

Student.prototype = {
constructor : Student,
toString : studentInfo
};

function task(){
var title = ["Assignment1","Assignment2","Assignment3","Assignment4","Assignment5","Mid Term", "Finals"]
var points = [30, 30, 28, 27, 29,41,45];
var titlePoints = "";
for (var i=0; i < points.length; i++){
titlePoints += title[i] + " : " + points[i] + "\n";
}
return titlePoints;
}


function studentInfo(){
return "Student : " + this.lastName + "," + this.firstName + "<br>"+ "eMail : " + this.email + "<br>" + "Course ID : " + this.courseID + "<br>" + "--------------------------------" + "<br>" + this.assignments;
}
var student = new Student("John", "Doe", "johndoe@gmail.com","COIN-070B.01");

</script>
</head>
<body>
<script type="text/javascript">
document.writeln(student.toString());
</script>
</body>
</html>

priyaa2002
10-04-2010, 07:41 PM
Can anyonle pls explain me why the return function is not returning the result as intended? I appreciate you help


OUTPUT
======

Student : Doe,John
eMail : johndoe@gmail.com
Course ID : COIN-070B.01
--------------------------------
function task() { var title = ["Assignment1", "Assignment2", "Assignment3", "Assignment4", "Assignment5", "Mid Term", "Finals"]; var points = [30, 30, 28, 27, 29, 41, 45]; for (var i = 0; i < points.length; i++) { titlePoints += title[i] + (" : " + points[i] + "\n"); } return titlePoints; }




<head>
<title>Variable - Examples 1</title>
<script type="text/javascript">
function Student(firstName, lastName, email,courseID){
this.firstName = firstName;
this.lastName = lastName;
this.email = email;
this.courseID = courseID;
this.assignments = task;
}

Student.prototype = {
constructor : Student,
toString : studentInfo
};

function task(){
var title = ["Assignment1","Assignment2","Assignment3","Assignment4","Assignment5","Mid Term", "Finals"]
var points = [30, 30, 28, 27, 29,41,45];
var titlePoints = "";
for (var i=0; i < points.length; i++){
titlePoints += title[i] + " : " + points[i] + "\n";
}
return titlePoints;
}


function studentInfo(){
return "Student : " + this.lastName + "," + this.firstName + "<br>"+ "eMail : " + this.email + "<br>" + "Course ID : " + this.courseID + "<br>" + "--------------------------------" + "<br>" + this.assignments;
}
var student = new Student("John", "Doe", "johndoe@gmail.com","COIN-070B.01");

</script>
</head>
<body>
<script type="text/javascript">
document.writeln(student.toString());
</script>
</body>
</html>

Philip M
10-04-2010, 07:45 PM
You have bumped and repeated your post within an hour. :( Please have a look at the forum rules.

DaveyErwin
10-04-2010, 07:57 PM
<head>
<title>Variable - Examples 1</title>
<script type="text/javascript">
function Student(firstName, lastName, email,courseID){
this.firstName = firstName;
this.lastName = lastName;
this.email = email;
this.courseID = courseID;
this.assignments = task;
}

Student.prototype = {
constructor : Student,
toString : studentInfo
};


function task(){
var title = ["Assignment1","Assignment2","Assignment3","Assignment4","Assignment5","Mid Term", "Finals"]
var points = [30, 30, 28, 27, 29,41,45];
var titlePoints = "";
for (var i=0; i < points.length; i++){
titlePoints += title[i] + " : " + points[i] + "\n";
}
return titlePoints;
}


function studentInfo(){
return "Student : " + this.lastName + "," + this.firstName + "<br>"+ "eMail : " + this.email + "<br>" + "Course ID : " + this.courseID + "<br>" + "--------------------------------" + "<br>" + this.assignments();
}
var student = new Student("John", "Doe", "johndoe@gmail.com","COIN-070B.01");

</script>
</head>
<body>
<script type="text/javascript">
document.writeln(student.toString());
</script>
</body>
</html>
you left out the ()
i put it in

priyaa2002
10-04-2010, 08:06 PM
Hello Philip, sorry I didn't intend to post the code twice. I'm new to this forum.. I didn't know how to delete the post.

priyaa2002
10-04-2010, 08:08 PM
for some reason this.assignments() is not working..But student.assignments() is working

DaveyErwin
10-04-2010, 08:18 PM
for some reason this.assignments() is not working..But student.assignments() is working

heres my results

Student : Doe,John
eMail : johndoe@gmail.com
Course ID : COIN-070B.01
--------------------------------
Assignment1 : 30 Assignment2 : 30 Assignment3 : 28 Assignment4 : 27 Assignment5 : 29 Mid Term : 41 Finals : 45

help me help you

priyaa2002
10-04-2010, 09:08 PM
Thanks Darwin



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum