Scripting (Blended)
3 credits
Page is correct and valid | 10 |
Constructor function complete and functioning | 25 |
add method created and functioning | 25 |
subtract method complete and functioning | 25 |
All output matches what is specified in the comments | 15 |
Total | 100 pts |
To practice with constructor functions, objects, and methods
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.
<!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>