forked from csarkar373/python-games
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstringquestionnc.js
More file actions
28 lines (25 loc) · 1008 Bytes
/
stringquestionnc.js
File metadata and controls
28 lines (25 loc) · 1008 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
27
28
import QuestionBaseClass from "../components/questionbaseclass";
import * as StringConstants from "./stringconstants";
function stringQuestionNC(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 = 2;
sq.rows = 1;
const length = currentWord.length;
const lowerBound = Math.floor(Math.random() * length);
for (let i = lowerBound; i < currentWord.length; ++i) {
sq.buttonStates[0][i] = 1;
}
sq.text = [` string = ${currentWord} `, `print(string[ ${lowerBound}: ])`];
return sq;
}
export default stringQuestionNC;