Number Methods

100 points

Number Methods

Requirements

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

Resources

Objective

To practice with constructor functions, objects, and methods

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>