Exercise 3: Calculate the Student's Total Marks

In this exercise, you have to calculate a student's total marks using the concept of prototypes in constructor functions.

We'll cover the following

Problem Statement

A constructor function called Student is given with the following parameters:

  • marks1
  • marks2

Important Note: Both marks1 and marks2 should be assigned to protected variables, _marks1 and _marks2, during initialization. The lesson on data encapsulation explains how to do so.

Next, you have to define the following methods such that they can be shared by all object instances created:

  • getMarks(markNumber): a method which should return _marks1 if markNumber equals 1 and _marks2 if markNumber equals 2.

  • calcTotal(): the method should return the sum of _marks1 and _marks2.

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy