Skip to content

Instantly share code, notes, and snippets.

@Mattteo1220
Created March 13, 2017 13:18
Show Gist options
  • Save Mattteo1220/019fd08b26d026175ccf806ad8df88f4 to your computer and use it in GitHub Desktop.
Save Mattteo1220/019fd08b26d026175ccf806ad8df88f4 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/fofaqox
<!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>
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