-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLetter.js
More file actions
29 lines (26 loc) · 1.05 KB
/
Copy pathLetter.js
File metadata and controls
29 lines (26 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//Letter.js: Contains a constructor, Letter.
class Letter {
constructor(character) {
//A string value to store the underlying character for the letter
this.letter = character;
//A boolean value that stores whether that letter has been guessed yet
this.guessed = false;
this.toString = function () {
//Returns the underlying character if the letter has been guessed
if (this.guessed) { return this.letter; }
else if (this.letter === " "){
return " "
}
//Returns a placeholder (underscore) if the letter has not been guessed
else { return "_"; }
};
this.checkCharacter = function (input) {
//Takes a character as an argument and checks it against the underlying character
if (input === this.letter)
//Updates the stored boolean value to true if it was guessed correctly
{ this.guessed = true; }
};
}
}
// exporting our Letter constructor
export default Letter;