Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 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 updateObject(obj) {
  12. // your code here
  13. obj.foo = 'foo';
  14. obj.bar = 'bar';
  15. obj.bizz = 'bizz';
  16. obj.bang = 'bang';
  17. return obj;
  18. }
  19.  
  20.  
  21.  
  22. /* From here down, you are not expected to
  23. understand.... for now :)
  24.  
  25.  
  26. Nothing to see here!
  27.  
  28. */
  29.  
  30. (function testUpdateObject() {
  31. var oldObj = {
  32. cats: 'cats',
  33. dogs: 'dogs',
  34. };
  35. var newObj = updateObject(oldObj);
  36. if (typeof newObj !== 'object') {
  37. console.error('ERROR: `createMyObject` must return an object');
  38. return false
  39. }
  40. ['foo', 'bar', 'bizz', 'bang'].forEach(function(key) {
  41. if (!(key in newObj)) {
  42. console.error('ERROR: `' + key + '` not in object returned by `updateObject`');
  43. return false;
  44. }
  45. });
  46. ['foo', 'bar', 'bizz', 'bang'].forEach(function(key) {
  47. if (newObj[key] !== key) {
  48. console.error('ERROR: `' + key + '` should be "' + key + '" but was ' + newObj[key]);
  49. return false;
  50. }
  51. });
  52. if (!(newObj.cats === 'cats' && newObj.dogs === 'dogs')) {
  53. console.error('ERROR: your function doesn\'t preserve existing key/value pairs');
  54. return false;
  55. }
  56. console.log('SUCCESS: `updateObject` works correctly!');
  57.  
  58. })();
  59. </script>
  60.  
  61.  
  62.  
  63. <script id="jsbin-source-javascript" type="text/javascript">function updateObject(obj) {
  64. // your code here
  65. obj.foo = 'foo';
  66. obj.bar = 'bar';
  67. obj.bizz = 'bizz';
  68. obj.bang = 'bang';
  69. return obj;
  70. }
  71.  
  72.  
  73.  
  74. /* From here down, you are not expected to
  75. understand.... for now :)
  76.  
  77.  
  78. Nothing to see here!
  79.  
  80. */
  81.  
  82. (function testUpdateObject() {
  83. var oldObj = {
  84. cats: 'cats',
  85. dogs: 'dogs',
  86. };
  87. var newObj = updateObject(oldObj);
  88. if (typeof newObj !== 'object') {
  89. console.error('ERROR: `createMyObject` must return an object');
  90. return false
  91. }
  92. ['foo', 'bar', 'bizz', 'bang'].forEach(function(key) {
  93. if (!(key in newObj)) {
  94. console.error('ERROR: `' + key + '` not in object returned by `updateObject`');
  95. return false;
  96. }
  97. });
  98. ['foo', 'bar', 'bizz', 'bang'].forEach(function(key) {
  99. if (newObj[key] !== key) {
  100. console.error('ERROR: `' + key + '` should be "' + key + '" but was ' + newObj[key]);
  101. return false;
  102. }
  103. });
  104. if (!(newObj.cats === 'cats' && newObj.dogs === 'dogs')) {
  105. console.error('ERROR: your function doesn\'t preserve existing key/value pairs');
  106. return false;
  107. }
  108. console.log('SUCCESS: `updateObject` works correctly!');
  109.  
  110. })();</script></body>
  111. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement