Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 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 createMyObject() {
  12. return {
  13. foo: 'bar',
  14. answerToUniverse: 42,
  15. 'olly olly': 'oxen free',
  16. sayHello: function() {
  17. return 'hello';
  18. }
  19. };}
  20.  
  21. (function testCreateMyObject() {
  22. var obj = createMyObject();
  23. if (typeof obj !== 'object') {
  24. console.error('ERROR: `createMyObject` must return an object');
  25. return false
  26. }
  27. var expectedKeys = ['foo', 'answerToUniverse', 'olly olly', 'sayHello'];
  28. expectedKeys.forEach(function(key) {
  29. if (!(key in obj)) {
  30. console.error('ERROR: Missing a key for ' + key);
  31. return false;
  32. }
  33. });
  34. if (obj.foo !== 'bar') {
  35. console.error('ERROR: Value for `foo` should be \'bar\' but was ' + obj.foo);
  36. return false;
  37. }
  38. if (obj.answerToUniverse !== 42) {
  39. console.error(
  40. 'ERROR: Value for `answerToUniverse` should be 42 but was ' + obj.answerToUniverse);
  41. return false;
  42. }
  43. if (obj['olly olly'] !== 'oxen free') {
  44. console.error(
  45. 'ERROR: Value for `\'olly olly\'` should be \'oxen free\' but was ' + obj['olly olly']);
  46. return false;
  47. }
  48. if (!(typeof obj.sayHello === "function" && obj.sayHello() === 'hello')) {
  49. console.error('ERROR: Value for `sayHello` must be a function that returns the string \'hello\'');
  50. return false;
  51. }
  52. console.log('SUCCESS: Your function works!');
  53. })();
  54. </script>
  55.  
  56.  
  57.  
  58. <script id="jsbin-source-javascript" type="text/javascript">function createMyObject() {
  59. return {
  60. foo: 'bar',
  61. answerToUniverse: 42,
  62. 'olly olly': 'oxen free',
  63. sayHello: function() {
  64. return 'hello';
  65. }
  66. };}
  67.  
  68. (function testCreateMyObject() {
  69. var obj = createMyObject();
  70. if (typeof obj !== 'object') {
  71. console.error('ERROR: `createMyObject` must return an object');
  72. return false
  73. }
  74. var expectedKeys = ['foo', 'answerToUniverse', 'olly olly', 'sayHello'];
  75. expectedKeys.forEach(function(key) {
  76. if (!(key in obj)) {
  77. console.error('ERROR: Missing a key for ' + key);
  78. return false;
  79. }
  80. });
  81. if (obj.foo !== 'bar') {
  82. console.error('ERROR: Value for `foo` should be \'bar\' but was ' + obj.foo);
  83. return false;
  84. }
  85. if (obj.answerToUniverse !== 42) {
  86. console.error(
  87. 'ERROR: Value for `answerToUniverse` should be 42 but was ' + obj.answerToUniverse);
  88. return false;
  89. }
  90. if (obj['olly olly'] !== 'oxen free') {
  91. console.error(
  92. 'ERROR: Value for `\'olly olly\'` should be \'oxen free\' but was ' + obj['olly olly']);
  93. return false;
  94. }
  95. if (!(typeof obj.sayHello === "function" && obj.sayHello() === 'hello')) {
  96. console.error('ERROR: Value for `sayHello` must be a function that returns the string \'hello\'');
  97. return false;
  98. }
  99. console.log('SUCCESS: Your function works!');
  100. })();
  101.  
  102. </script></body>
  103. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement