Threesuns

Email the Instructor

Contact

All Semesters

Semesters

All Courses

Courses

2017Spring

01.09.17 - 05.07.17

Scripting (Blended)

CSYS2033

Monday
02:30 PM - 03:50 PM

Number Methods

Lab03

Objective: To practice with constructor functions, objects, and methods

pastdue

Submit Your Solution

Lab03

Request a Copy of your Solution

Lab03

Requirements

Page is correct and valid10 pts
Constructor function complete and functioning25 pts
add method created and functioning25 pts
subtract method complete and functioning25 pts
All output matches what is specified in the comments15 pts
Total100 pts

Instructions

The code shown in the head section below is incomplete. You will need to complete the code in the head section by finishing the Number constructor function and adding methods to it so that the code in the body will execute without errors and will produce the output specified in the comments.

Incomplete Code

<!DOCTYPE html>
  <head>
    <meta charset="utf-8">
    <title>Number Methods</title>
    <meta name="viewport" content="width=device-width">
    <script type="text/javascript">
      function Number( value ) {

      }
    </script>
  </head>
  <body>
    <h1>Number Methods</h1>
    <script type="text/javascript">
      var num1 = new Number( 3 );
      var num2 = new Number( 9 );

      // should output "num1 is: 3<br/>"
      document.writeln( "num1 is: " + num1.value + "<br/>" );

      // should output "num2 is: 9<br/>"
      document.writeln( "num2 is: " + num2.value + "<br/>" );

      // should output "num1 + num2 is: 12<br/>"
      document.writeln( "num1 + num2 is: " + num1.add( num2 ) + "<br/>" );

      // should output "num2 - num1 is: 6<br/>"
      document.writeln( "num2 - num1 is: " + num2.subtract( num1 ) + "<br/>" );
    </script>
  </body>
</html>