Created
March 13, 2017 13:18
-
-
Save Mattteo1220/019fd08b26d026175ccf806ad8df88f4 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/fofaqox
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 personMaker() { | |
var person = { | |
firstName: 'Paul', | |
lastName: 'Jones', | |
// replace `null` with a function that uses self reference to return | |
// full name | |
fullName: function() { | |
return this.firstName + " " + this.lastName | |
} | |
}; | |
return person; | |
} | |
/* From here down, you are not expected to | |
understand.... for now :) | |
Nothing to see here! | |
*/ | |
(function testPersonMaker() { | |
var person = personMaker(); | |
if (typeof person !== 'object') { | |
console.error('ERROR: `personMaker` must return an object'); | |
return false | |
} | |
if (typeof person.fullName !== 'function') { | |
console.error('ERROR: `fullName` must be a method'); | |
return false | |
} | |
if (person.fullName() !== 'Paul Jones') { | |
console.error('ERROR: The value for `fullName` should be "Paul Jones" but was ' + person.fullName()); | |
return false; | |
} | |
person.firstName = 'Lisa'; | |
person.lastName = 'Simpson'; | |
if (person.fullName() !== 'Lisa Simpson') { | |
console.error( | |
'`personMaker` is not using self reference correctly. ' + | |
'When firstName set to "Lisa" and lastName set to "Simpson", ' + | |
'should return "Lisa Simpson" but returned ' + person.fullName() | |
) | |
} | |
console.log('SUCCESS: `updateObject` works correctly!'); | |
})(); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">function personMaker() { | |
var person = { | |
firstName: 'Paul', | |
lastName: 'Jones', | |
// replace `null` with a function that uses self reference to return | |
// full name | |
fullName: function() { | |
return this.firstName + " " + this.lastName | |
} | |
}; | |
return person; | |
} | |
/* From here down, you are not expected to | |
understand.... for now :) | |
Nothing to see here! | |
*/ | |
(function testPersonMaker() { | |
var person = personMaker(); | |
if (typeof person !== 'object') { | |
console.error('ERROR: `personMaker` must return an object'); | |
return false | |
} | |
if (typeof person.fullName !== 'function') { | |
console.error('ERROR: `fullName` must be a method'); | |
return false | |
} | |
if (person.fullName() !== 'Paul Jones') { | |
console.error('ERROR: The value for `fullName` should be "Paul Jones" but was ' + person.fullName()); | |
return false; | |
} | |
person.firstName = 'Lisa'; | |
person.lastName = 'Simpson'; | |
if (person.fullName() !== 'Lisa Simpson') { | |
console.error( | |
'`personMaker` is not using self reference correctly. ' + | |
'When firstName set to "Lisa" and lastName set to "Simpson", ' + | |
'should return "Lisa Simpson" but returned ' + person.fullName() | |
) | |
} | |
console.log('SUCCESS: `updateObject` works correctly!'); | |
})();</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 personMaker() { | |
var person = { | |
firstName: 'Paul', | |
lastName: 'Jones', | |
// replace `null` with a function that uses self reference to return | |
// full name | |
fullName: function() { | |
return this.firstName + " " + this.lastName | |
} | |
}; | |
return person; | |
} | |
/* From here down, you are not expected to | |
understand.... for now :) | |
Nothing to see here! | |
*/ | |
(function testPersonMaker() { | |
var person = personMaker(); | |
if (typeof person !== 'object') { | |
console.error('ERROR: `personMaker` must return an object'); | |
return false | |
} | |
if (typeof person.fullName !== 'function') { | |
console.error('ERROR: `fullName` must be a method'); | |
return false | |
} | |
if (person.fullName() !== 'Paul Jones') { | |
console.error('ERROR: The value for `fullName` should be "Paul Jones" but was ' + person.fullName()); | |
return false; | |
} | |
person.firstName = 'Lisa'; | |
person.lastName = 'Simpson'; | |
if (person.fullName() !== 'Lisa Simpson') { | |
console.error( | |
'`personMaker` is not using self reference correctly. ' + | |
'When firstName set to "Lisa" and lastName set to "Simpson", ' + | |
'should return "Lisa Simpson" but returned ' + person.fullName() | |
) | |
} | |
console.log('SUCCESS: `updateObject` works correctly!'); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment