Changeset View
Changeset View
Standalone View
Standalone View
src/activities/algebra_by/algebra.js
Show All 21 Lines | |||||
22 | 22 | | |||
23 | var currentLevel | 23 | var currentLevel | ||
24 | var coreItems | 24 | var coreItems | ||
25 | var otherItems | 25 | var otherItems | ||
26 | var operand | 26 | var operand | ||
27 | var secondOperandVal | 27 | var secondOperandVal | ||
28 | var firstOperandVal | 28 | var firstOperandVal | ||
29 | var operations = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] | 29 | var operations = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] | ||
30 | var OperandsEnum = { | ||||
31 | TIMES_SIGN : "\u00D7", | ||||
32 | PLUS_SIGN : "\u002B", | ||||
33 | MINUS_SIGN : "\u2212", | ||||
34 | DIVIDE_SIGN : "\u2215" | ||||
35 | } | ||||
30 | 36 | | |||
31 | var nbLevel = operations.length | 37 | var nbLevel = operations.length | ||
32 | 38 | | |||
33 | function start(coreItems_, otherItems_, operand_) { | 39 | function start(coreItems_, otherItems_, operand_) { | ||
34 | operand = operand_ | 40 | operand = operand_ | ||
35 | coreItems = coreItems_ | 41 | coreItems = coreItems_ | ||
36 | otherItems = otherItems_ | 42 | otherItems = otherItems_ | ||
37 | currentLevel = 0 | 43 | currentLevel = 0 | ||
38 | coreItems.score.numberOfSubLevels = 10 | 44 | coreItems.score.numberOfSubLevels = 10 | ||
39 | // for multiplication and addition, the first levels will display | 45 | // for multiplication and addition, the first levels will display | ||
40 | // currentLevel * N (N behind random) | 46 | // currentLevel * N (N behind random) | ||
41 | // where the last levels will do: | 47 | // where the last levels will do: | ||
42 | // N * currentLevel | 48 | // N * currentLevel | ||
43 | if(operand.text === "x" || operand.text === "+") | 49 | if(operand.text === OperandsEnum.TIMES_SIGN || operand.text === OperandsEnum.PLUS_SIGN) | ||
44 | nbLevel = 2 * operations.length | 50 | nbLevel = 2 * operations.length | ||
45 | else | 51 | else | ||
46 | nbLevel = operations.length | 52 | nbLevel = operations.length | ||
47 | initLevel() | 53 | initLevel() | ||
48 | } | 54 | } | ||
49 | 55 | | |||
50 | function stop() { | 56 | function stop() { | ||
51 | coreItems.balloon.stopMoving() | 57 | coreItems.balloon.stopMoving() | ||
Show All 25 Lines | 80 | function previousLevel() { | |||
77 | } | 83 | } | ||
78 | initLevel(); | 84 | initLevel(); | ||
79 | } | 85 | } | ||
80 | 86 | | |||
81 | function calculateOperands() | 87 | function calculateOperands() | ||
82 | { | 88 | { | ||
83 | switch(operand.text) | 89 | switch(operand.text) | ||
84 | { | 90 | { | ||
85 | case "x": | 91 | case OperandsEnum.TIMES_SIGN: | ||
86 | firstOperandVal = coreItems.bar.level | 92 | firstOperandVal = coreItems.bar.level | ||
87 | secondOperandVal = operations[coreItems.score.currentSubLevel - 1] | 93 | secondOperandVal = operations[coreItems.score.currentSubLevel - 1] | ||
88 | break; | 94 | break; | ||
89 | case "+": | 95 | case OperandsEnum.PLUS_SIGN: | ||
90 | firstOperandVal = coreItems.bar.level | 96 | firstOperandVal = coreItems.bar.level | ||
91 | secondOperandVal = operations[coreItems.score.currentSubLevel - 1] | 97 | secondOperandVal = operations[coreItems.score.currentSubLevel - 1] | ||
92 | break; | 98 | break; | ||
93 | case "-": | 99 | case OperandsEnum.MINUS_SIGN: | ||
94 | firstOperandVal = coreItems.bar.level + 9 | 100 | firstOperandVal = coreItems.bar.level + 9 | ||
95 | secondOperandVal = operations[coreItems.score.currentSubLevel - 1] | 101 | secondOperandVal = operations[coreItems.score.currentSubLevel - 1] | ||
96 | break; | 102 | break; | ||
97 | case "/": | 103 | case OperandsEnum.DIVIDE_SIGN: | ||
98 | firstOperandVal = coreItems.bar.level * operations[coreItems.score.currentSubLevel - 1] | 104 | firstOperandVal = coreItems.bar.level * operations[coreItems.score.currentSubLevel - 1] | ||
99 | secondOperandVal = coreItems.bar.level | 105 | secondOperandVal = coreItems.bar.level | ||
100 | break; | 106 | break; | ||
101 | } | 107 | } | ||
102 | 108 | | |||
103 | if(currentLevel < operations.length) { | 109 | if(currentLevel < operations.length) { | ||
104 | otherItems.firstOp.text = firstOperandVal | 110 | otherItems.firstOp.text = firstOperandVal | ||
105 | otherItems.secondOp.text = secondOperandVal | 111 | otherItems.secondOp.text = secondOperandVal | ||
106 | } else { | 112 | } else { | ||
107 | otherItems.firstOp.text = secondOperandVal | 113 | otherItems.firstOp.text = secondOperandVal | ||
108 | // Don't forget to remove the first operations.length levels | 114 | // Don't forget to remove the first operations.length levels | ||
109 | firstOperandVal -= operations.length | 115 | firstOperandVal -= operations.length | ||
110 | otherItems.secondOp.text = firstOperandVal | 116 | otherItems.secondOp.text = firstOperandVal | ||
111 | } | 117 | } | ||
112 | } | 118 | } | ||
113 | 119 | | |||
114 | // Return the expected answer | 120 | // Return the expected answer | ||
115 | function getAnswer() { | 121 | function getAnswer() { | ||
116 | switch(operand.text) | 122 | switch(operand.text) | ||
117 | { | 123 | { | ||
118 | case "x": | 124 | case OperandsEnum.TIMES_SIGN: | ||
119 | return (firstOperandVal * secondOperandVal) | 125 | return (firstOperandVal * secondOperandVal) | ||
120 | 126 | | |||
121 | case "+": | 127 | case OperandsEnum.PLUS_SIGN: | ||
122 | return (firstOperandVal + secondOperandVal) | 128 | return (firstOperandVal + secondOperandVal) | ||
123 | 129 | | |||
124 | case "-": | 130 | case OperandsEnum.MINUS_SIGN: | ||
125 | return (firstOperandVal - secondOperandVal) | 131 | return (firstOperandVal - secondOperandVal) | ||
126 | 132 | | |||
127 | case "/": | 133 | case OperandsEnum.DIVIDE_SIGN: | ||
128 | return (firstOperandVal / secondOperandVal) | 134 | return (firstOperandVal / secondOperandVal) | ||
129 | } | 135 | } | ||
130 | } | 136 | } | ||
131 | 137 | | |||
132 | function validateAnswer(screenAnswer) | 138 | function validateAnswer(screenAnswer) | ||
133 | { | 139 | { | ||
134 | return (getAnswer() === screenAnswer) | 140 | return (getAnswer() === screenAnswer) | ||
135 | } | 141 | } | ||
Show All 30 Lines |