Skip to content

Spell Constructors #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions constructors.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,33 @@
* @property {string} description
* @method printDetails
*/

function Spell (name, cost, description) {
if (typeof(name) === 'string') {
this.name = name;
} else {
throw new TypeError('Spell name must be a string.');
}
if (typeof(cost) === 'number') {
this.cost = cost;
} else {
throw new TypeError('Spell cost must be a number.');
}
if (typeof(description) === 'string') {
this.description = description;
} else {
throw new TypeError('Spell description must be a string.');
}
/**
* Returns a string of all of the spell's details.
* The format doesn't matter, as long as it contains the spell name, cost, and description.
*
* @name getDetails
* @return {string} details containing all of the spells information.
*/

this.getDetails = function () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure you are adding these to the Spell.prototype instead of as instance methods.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I did after I committed because I started noticing places I wanted to use prototype instead.

return 'Spell Name: ' + name + ', Spell Cost: ' + cost + ', Spell Description: ' + description;
};
}
/**
* A spell that deals damage.
* We want to keep this code DRY (Don't Repeat Yourself).
Expand Down