Guest User

Untitled

a guest
Jul 15th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. function createMyObject() {
  2. // your code here
  3. return {
  4. foo: 'bar',
  5. answerToUniverse: 42,
  6. 'olly olly': 'oxen free',
  7. sayHello: function() {
  8. return 'hello';
  9. },
  10. };
  11. }
  12.  
  13. /* From here down, you are not expected to
  14. understand.... for now :)
  15.  
  16.  
  17. Nothing to see here!
  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 ' +
  41. obj.answerToUniverse
  42. );
  43. return false;
  44. }
  45. if (obj['olly olly'] !== 'oxen free') {
  46. console.error(
  47. "ERROR: Value for `'olly olly'` should be 'oxen free' but was " +
  48. obj['olly olly']
  49. );
  50. return false;
  51. }
  52. if (!(typeof obj.sayHello === 'function' && obj.sayHello() === 'hello')) {
  53. console.error(
  54. "ERROR: Value for `sayHello` must be a function that returns the string 'hello'"
  55. );
  56. return false;
  57. }
  58. console.log('SUCCESS: Your function works!');
  59. })();
Add Comment
Please, Sign In to add comment