-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
44 lines (44 loc) · 1.63 KB
/
app.js
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConverterOfNumber = void 0;
var ConverterNumber = /** @class */ (function () {
function ConverterNumber() {
this.userInput = "";
this.correctAnswerValue = "";
this.correctAnswerFun = function () { };
this.incorrectAnswerFun = function () { };
}
ConverterNumber.prototype.setUserInput = function (userInput) {
this.userInput = userInput;
return this;
};
ConverterNumber.prototype.setCorrectAnswer = function (correctAnswer) {
this.correctAnswerValue = correctAnswer;
return this;
};
ConverterNumber.prototype.setAnswers = function (correctAnswerFun, incorrectAnswerFun) {
this.correctAnswerFun = correctAnswerFun;
this.incorrectAnswerFun = incorrectAnswerFun;
return this;
};
ConverterNumber.prototype.convertNumber = function (input) {
return parseFloat(input.replace(",", "."));
};
ConverterNumber.prototype.checkAnswer = function () {
var userNumber = this.convertNumber(this.userInput);
if (!isNaN(userNumber)) {
if (userNumber === this.convertNumber(this.correctAnswerValue)) {
this.correctAnswerFun(this.userInput, this.correctAnswerValue);
}
else {
this.incorrectAnswerFun(this.userInput, this.correctAnswerValue);
}
}
else {
this.incorrectAnswerFun(this.userInput, this.correctAnswerValue);
}
return this;
};
return ConverterNumber;
}());
exports.ConverterOfNumber = new ConverterNumber();