Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Oct 2010
    Posts
    13
    Thanks
    4
    Thanked 0 Times in 0 Posts

    function result not displayed

    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; }


    Code:
    <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>
    Last edited by priyaa2002; 10-04-2010 at 06:57 PM.

  • #2
    New Coder
    Join Date
    Oct 2010
    Posts
    13
    Thanks
    4
    Thanked 0 Times in 0 Posts

    function not returning result

    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; }


    Code:
    <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>

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,990
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    You have bumped and repeated your post within an hour. Please have a look at the forum rules.

  • #4
    Regular Coder
    Join Date
    Aug 2010
    Posts
    970
    Thanks
    19
    Thanked 212 Times in 210 Posts
    Code:
    <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

  • Users who have thanked DaveyErwin for this post:

    priyaa2002 (10-04-2010)

  • #5
    New Coder
    Join Date
    Oct 2010
    Posts
    13
    Thanks
    4
    Thanked 0 Times in 0 Posts
    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.

  • #6
    New Coder
    Join Date
    Oct 2010
    Posts
    13
    Thanks
    4
    Thanked 0 Times in 0 Posts
    for some reason this.assignments() is not working..But student.assignments() is working

  • #7
    Regular Coder
    Join Date
    Aug 2010
    Posts
    970
    Thanks
    19
    Thanked 212 Times in 210 Posts
    Quote Originally Posted by priyaa2002 View Post
    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

  • #8
    New Coder
    Join Date
    Oct 2010
    Posts
    13
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Thanks Darwin

    Thanks Darwin


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •