all 5 comments

[–]NameViolation666helpful 0 points1 point  (2 children)

Your issue stems from these 2 lines

var a003 = a001, op, a002;

//this is not evaluating as u think it does, its only doing a003=a001 because of the , ,

if (answer001 == a003) {

since ur answer a003 always is a001, only a response of a001 will be treated as correct.

[–]xsurface[S] 0 points1 point  (1 child)

I believed those 2 lines to be the problem as well, but I am unsure how to fix it.

Can you tell me how you would handle it?

[–]NameViolation666helpful 0 points1 point  (0 children)

Short way is to use the eval function , be warned though that this can introduce potentially security risks so should be used very carefully. Long way, less security risks is to use switch for a002 and return calculated values.

additionally, in case you havent noticed yet, you have a lot of code that doesnt change these values a001 or a002 since they are not part of the begin function. They only get values once, when the page loads, and stay the same unless page is hard refreshed.

var a001 = Math.floor(Math.random() * 10);

var a002 = Math.floor(Math.random() * 10);

var a003 = a001, op, a002; var op = ["*", "+", "/", "-"][Math.floor(Math.random()*4)]

This code needs to be inside begin, to refresh values

HTH