forked from csarkar373/python-games
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstringquestioncn.js
More file actions
26 lines (24 loc) · 977 Bytes
/
stringquestioncn.js
File metadata and controls
26 lines (24 loc) · 977 Bytes
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
import QuestionBaseClass from "../components/questionbaseclass";
import * as StringConstants from "./stringconstants";
function stringQuestionCN(props) {
//pick a word from the word pool at random
const wordIndex = StringConstants.WORDPOOL.length;
const currentWord =
StringConstants.WORDPOOL[Math.floor(Math.random() * wordIndex)];
// question will have 1 row and 8 columns
const sq = new QuestionBaseClass(props, 1, currentWord.length);
// adjust the button display values
for (let i = 0; i < currentWord.length; ++i) {
sq.displayValues[0][i] = currentWord.substring(i, i + 1);
}
//console.log("array question base class", sq);
sq.pointValue = 1;
sq.rows = 1;
const upperBound = Math.floor(Math.random() * (currentWord.length - 1)) + 1;
for (let i = 0; i < upperBound; ++i) {
sq.buttonStates[0][i] = 1;
}
sq.text = [`string = "${currentWord}"`, `print(string[ : ${upperBound} ])`];
return sq;
}
export default stringQuestionCN;