Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width">
- <title>JS Bin</title>
- </head>
- <body>
- <script id="jsbin-javascript">
- function updateObject(obj) {
- // your code here
- obj.foo = 'foo';
- obj.bar = 'bar';
- obj.bizz = 'bizz';
- obj.bang = 'bang';
- return obj;
- }
- /* From here down, you are not expected to
- understand.... for now :)
- Nothing to see here!
- */
- (function testUpdateObject() {
- var oldObj = {
- cats: 'cats',
- dogs: 'dogs',
- };
- var newObj = updateObject(oldObj);
- if (typeof newObj !== 'object') {
- console.error('ERROR: `createMyObject` must return an object');
- return false
- }
- ['foo', 'bar', 'bizz', 'bang'].forEach(function(key) {
- if (!(key in newObj)) {
- console.error('ERROR: `' + key + '` not in object returned by `updateObject`');
- return false;
- }
- });
- ['foo', 'bar', 'bizz', 'bang'].forEach(function(key) {
- if (newObj[key] !== key) {
- console.error('ERROR: `' + key + '` should be "' + key + '" but was ' + newObj[key]);
- return false;
- }
- });
- if (!(newObj.cats === 'cats' && newObj.dogs === 'dogs')) {
- console.error('ERROR: your function doesn\'t preserve existing key/value pairs');
- return false;
- }
- console.log('SUCCESS: `updateObject` works correctly!');
- })();
- </script>
- <script id="jsbin-source-javascript" type="text/javascript">function updateObject(obj) {
- // your code here
- obj.foo = 'foo';
- obj.bar = 'bar';
- obj.bizz = 'bizz';
- obj.bang = 'bang';
- return obj;
- }
- /* From here down, you are not expected to
- understand.... for now :)
- Nothing to see here!
- */
- (function testUpdateObject() {
- var oldObj = {
- cats: 'cats',
- dogs: 'dogs',
- };
- var newObj = updateObject(oldObj);
- if (typeof newObj !== 'object') {
- console.error('ERROR: `createMyObject` must return an object');
- return false
- }
- ['foo', 'bar', 'bizz', 'bang'].forEach(function(key) {
- if (!(key in newObj)) {
- console.error('ERROR: `' + key + '` not in object returned by `updateObject`');
- return false;
- }
- });
- ['foo', 'bar', 'bizz', 'bang'].forEach(function(key) {
- if (newObj[key] !== key) {
- console.error('ERROR: `' + key + '` should be "' + key + '" but was ' + newObj[key]);
- return false;
- }
- });
- if (!(newObj.cats === 'cats' && newObj.dogs === 'dogs')) {
- console.error('ERROR: your function doesn\'t preserve existing key/value pairs');
- return false;
- }
- console.log('SUCCESS: `updateObject` works correctly!');
- })();</script></body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement