quote:
Originally posted by roflmao456
sometimes returns undefined in the message.
example : when doing 1+1 it sometimes (rarely) returns 1undefined1..
hope someone can fix..?
BEDMAS
Brackets
Exponents
Division
Muliplication
Addition
Subtraction.
code:
randomop=Math.round(Math.random()*(op.length)-1);
The order of the code that would be processed first is as follows
code:
randomop=Math.round(Math.random()*(op.length)-1);
| |________| |
| | | |
| |_ processed first
|_______________________| |
| | |
| |_ processed second
| |
| |
|_________________________|
|
|_ processed third
So with your code if the random number generated is 0 then once you subtract 1 you end up with -1 as a value and there is no operator at array position -1.
code:
randomop=Math.round(Math.random()*(op.length-1));
Is the right code.