Fix of invalid .this usage, fix for question getting with no answers shown, basic assert add

This commit is contained in:
YourFriendlyNeighborhoodDealer 2019-03-13 13:36:15 +01:00
parent 1a710fcd42
commit 580f9d9b9c

34
main.js
View file

@ -27,7 +27,7 @@ const serverAdress = "https://qmining.tk/";
// forcing pages for testing. unless you test, do not set these to true!
// only one of these should be true for testing
const forceTestPage = true;
const forceTestPage = false;
const forceResultPage = false;
const forceDefaultPage = false;
const logElementGetting = false;
@ -535,32 +535,32 @@ class ResultsPageModell {
// the basic type of getting answers
fun.push(function TryGet0(i) {
var temp = this.GetRightAnswerIfCorrectShown(i); // getting risht answer
var temp = RPM.GetRightAnswerIfCorrectShown(i); // getting risht answer
if (temp.length > 0) // if the rightanswer element is not 0 length
return temp[0].innerText; // adding the answer to curr question as .a
});
// if there is dropdown list in the current question
fun.push(function TryGet1(i) {
if (this.GetDropboxes(i).length > 0)
return this.GetCurrentAnswer(i);
if (RPM.GetDropboxes(i).length > 0)
return RPM.GetCurrentAnswer(i);
});
// if the correct answers are not shown, and the selected answer
// is correct
fun.push(function TryGet2(i) {
return this.GetRightAnswerIfCorrectNotShown(i);
return RPM.GetRightAnswerIfCorrectNotShown(i);
});
// if there is dropbox in the question
fun.push(function TryGet3(i) {
return this.GetSelectAnswer();
return RPM.GetSelectAnswer();
});
// if the correct answers are not shown, and the selected answer
// is incorrect, and there are only 2 options
fun.push(function TryGet4(i) {
var possibleAnswers = this.GetPossibleAnswers(i);
var possibleAnswers = RPM.GetPossibleAnswers(i);
if (possibleAnswers.length == 2) {
for (var k = 0; k < possibleAnswers.length; k++)
if (possibleAnswers[k].iscorrect == undefined)
@ -691,7 +691,8 @@ function Main() {
console.timeEnd('main');
if (forceTestPage || forceResultPage || forceDefaultPage)
document.getElementById("scriptMessage").style.background = "green";
if (document.getElementById("scriptMessage"))
document.getElementById("scriptMessage").style.background = "green";
}
//: }}}
@ -1383,14 +1384,16 @@ function GetQuiz() {
var img = GetImageFormResult(i);
question.i = img;
q = ReplaceCharsWithSpace(q, "\n");
a = ReplaceCharsWithSpace(a, "\n");
if (q != undefined)
q = ReplaceCharsWithSpace(q, "\n");
if (a != undefined)
a = ReplaceCharsWithSpace(a, "\n");
if (question.a != undefined) // adding only if has question
{
quiz.push(new Question(question.q, question.a, question.i)); // adding current question to quiz
} else {
Log("error getting queston, or its incorrect");
Log("error getting queston, no correct answer given, or its incorrect");
Log(question);
}
}
@ -2186,6 +2189,10 @@ function CreateNodeWithText(to, text, type) {
}
function ReplaceCharsWithSpace(val, char) {
assert(val);
assert(char);
toremove = NormalizeSpaces(val);
var regex = new RegExp(char, "g");
@ -2243,6 +2250,11 @@ function SendXHRMessage(message) {
});
}
var assert = (val) => {
if (!val)
throw new Error("Assertion failed");
};
//: }}}
//: Help {{{