Created
March 13, 2017 13:07
-
-
Save Mattteo1220/b24f87e4335bc1afc30f1e2d2e78e9a2 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/zobixok
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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 createMyObject() { | |
return { | |
foo: 'bar', | |
answerToUniverse: 42, | |
'olly olly' : 'oxen free', | |
sayHello: function(){ | |
return 'hello' | |
} | |
}; | |
} | |
/* From here down, you are not expected to | |
understand.... for now :) | |
Nothing to see here! | |
*/ | |
(function testCreateMyObject() { | |
var obj = createMyObject(); | |
if (typeof obj !== 'object') { | |
console.error('ERROR: `createMyObject` must return an object'); | |
return false | |
} | |
var expectedKeys = ['foo', 'answerToUniverse', 'olly olly', 'sayHello']; | |
expectedKeys.forEach(function(key) { | |
if (!(key in obj)) { | |
console.error('ERROR: Missing a key for ' + key); | |
return false; | |
} | |
}); | |
if (obj.foo !== 'bar') { | |
console.error('ERROR: Value for `foo` should be \'bar\' but was ' + obj.foo); | |
return false; | |
} | |
if (obj.answerToUniverse !== 42) { | |
console.error( | |
'ERROR: Value for `answerToUniverse` should be 42 but was ' + obj.answerToUniverse); | |
return false; | |
} | |
if (obj['olly olly'] !== 'oxen free') { | |
console.error( | |
'ERROR: Value for `\'olly olly\'` should be \'oxen free\' but was ' + obj['olly olly']); | |
return false; | |
} | |
if (!(typeof obj.sayHello === "function" && obj.sayHello() === 'hello')) { | |
console.error('ERROR: Value for `sayHello` must be a function that returns the string \'hello\''); | |
return false; | |
} | |
console.log('SUCCESS: Your function works!'); | |
})(); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">function createMyObject() { | |
return { | |
foo: 'bar', | |
answerToUniverse: 42, | |
'olly olly' : 'oxen free', | |
sayHello: function(){ | |
return 'hello' | |
} | |
}; | |
} | |
/* From here down, you are not expected to | |
understand.... for now :) | |
Nothing to see here! | |
*/ | |
(function testCreateMyObject() { | |
var obj = createMyObject(); | |
if (typeof obj !== 'object') { | |
console.error('ERROR: `createMyObject` must return an object'); | |
return false | |
} | |
var expectedKeys = ['foo', 'answerToUniverse', 'olly olly', 'sayHello']; | |
expectedKeys.forEach(function(key) { | |
if (!(key in obj)) { | |
console.error('ERROR: Missing a key for ' + key); | |
return false; | |
} | |
}); | |
if (obj.foo !== 'bar') { | |
console.error('ERROR: Value for `foo` should be \'bar\' but was ' + obj.foo); | |
return false; | |
} | |
if (obj.answerToUniverse !== 42) { | |
console.error( | |
'ERROR: Value for `answerToUniverse` should be 42 but was ' + obj.answerToUniverse); | |
return false; | |
} | |
if (obj['olly olly'] !== 'oxen free') { | |
console.error( | |
'ERROR: Value for `\'olly olly\'` should be \'oxen free\' but was ' + obj['olly olly']); | |
return false; | |
} | |
if (!(typeof obj.sayHello === "function" && obj.sayHello() === 'hello')) { | |
console.error('ERROR: Value for `sayHello` must be a function that returns the string \'hello\''); | |
return false; | |
} | |
console.log('SUCCESS: Your function works!'); | |
})(); | |
</script></body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createMyObject() { | |
return { | |
foo: 'bar', | |
answerToUniverse: 42, | |
'olly olly' : 'oxen free', | |
sayHello: function(){ | |
return 'hello' | |
} | |
}; | |
} | |
/* From here down, you are not expected to | |
understand.... for now :) | |
Nothing to see here! | |
*/ | |
(function testCreateMyObject() { | |
var obj = createMyObject(); | |
if (typeof obj !== 'object') { | |
console.error('ERROR: `createMyObject` must return an object'); | |
return false | |
} | |
var expectedKeys = ['foo', 'answerToUniverse', 'olly olly', 'sayHello']; | |
expectedKeys.forEach(function(key) { | |
if (!(key in obj)) { | |
console.error('ERROR: Missing a key for ' + key); | |
return false; | |
} | |
}); | |
if (obj.foo !== 'bar') { | |
console.error('ERROR: Value for `foo` should be \'bar\' but was ' + obj.foo); | |
return false; | |
} | |
if (obj.answerToUniverse !== 42) { | |
console.error( | |
'ERROR: Value for `answerToUniverse` should be 42 but was ' + obj.answerToUniverse); | |
return false; | |
} | |
if (obj['olly olly'] !== 'oxen free') { | |
console.error( | |
'ERROR: Value for `\'olly olly\'` should be \'oxen free\' but was ' + obj['olly olly']); | |
return false; | |
} | |
if (!(typeof obj.sayHello === "function" && obj.sayHello() === 'hello')) { | |
console.error('ERROR: Value for `sayHello` must be a function that returns the string \'hello\''); | |
return false; | |
} | |
console.log('SUCCESS: Your function works!'); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment