Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width">
  6. <title>JS Bin</title>
  7. </head>
  8. <body>
  9.  
  10. <script id="jsbin-javascript">
  11. function personMaker() {
  12. var person = {
  13. firstName: 'Paul',
  14. lastName: 'Jones',
  15. // replace `null` with a function that uses self reference to return
  16. // full name
  17. fullName: function() {
  18. return this.firstName + " " + this.lastName;
  19. }
  20. };
  21. return person;
  22. }
  23.  
  24.  
  25.  
  26. /* From here down, you are not expected to
  27. understand.... for now :)
  28.  
  29.  
  30. Nothing to see here!
  31.  
  32. */
  33.  
  34. (function testPersonMaker() {
  35. var person = personMaker();
  36. if (typeof person !== 'object') {
  37. console.error('ERROR: `personMaker` must return an object');
  38. return false
  39. }
  40. if (typeof person.fullName !== 'function') {
  41. console.error('ERROR: `fullName` must be a method');
  42. return false
  43. }
  44. if (person.fullName() !== 'Paul Jones') {
  45. console.error('ERROR: The value for `fullName` should be "Paul Jones" but was ' + person.fullName());
  46. return false;
  47. }
  48. person.firstName = 'Lisa';
  49. person.lastName = 'Simpson';
  50. if (person.fullName() !== 'Lisa Simpson') {
  51. console.error(
  52. '`personMaker` is not using self reference correctly. ' +
  53. 'When firstName set to "Lisa" and lastName set to "Simpson", ' +
  54. 'should return "Lisa Simpson" but returned ' + person.fullName()
  55. )
  56. }
  57. console.log('SUCCESS: `updateObject` works correctly!');
  58.  
  59. })();
  60. </script>
  61.  
  62.  
  63.  
  64. <script id="jsbin-source-javascript" type="text/javascript">function personMaker() {
  65. var person = {
  66. firstName: 'Paul',
  67. lastName: 'Jones',
  68. // replace `null` with a function that uses self reference to return
  69. // full name
  70. fullName: function() {
  71. return this.firstName + " " + this.lastName;
  72. }
  73. };
  74. return person;
  75. }
  76.  
  77.  
  78.  
  79. /* From here down, you are not expected to
  80. understand.... for now :)
  81.  
  82.  
  83. Nothing to see here!
  84.  
  85. */
  86.  
  87. (function testPersonMaker() {
  88. var person = personMaker();
  89. if (typeof person !== 'object') {
  90. console.error('ERROR: `personMaker` must return an object');
  91. return false
  92. }
  93. if (typeof person.fullName !== 'function') {
  94. console.error('ERROR: `fullName` must be a method');
  95. return false
  96. }
  97. if (person.fullName() !== 'Paul Jones') {
  98. console.error('ERROR: The value for `fullName` should be "Paul Jones" but was ' + person.fullName());
  99. return false;
  100. }
  101. person.firstName = 'Lisa';
  102. person.lastName = 'Simpson';
  103. if (person.fullName() !== 'Lisa Simpson') {
  104. console.error(
  105. '`personMaker` is not using self reference correctly. ' +
  106. 'When firstName set to "Lisa" and lastName set to "Simpson", ' +
  107. 'should return "Lisa Simpson" but returned ' + person.fullName()
  108. )
  109. }
  110. console.log('SUCCESS: `updateObject` works correctly!');
  111.  
  112. })();</script></body>
  113. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement