I'm writing a small webpage that will enable students to answer questions and get feedback on their answers.
Part of this detection checks for common errors to give them guidance. Specifically I want to check if their answer is a power of ten out from the actual answer.
If the answer was 3.93E-6, this condition should activate if they type 3.93E2, 3.93E-9, 3.93 etc.
The obvious way to me to test this is to do something like this:
var correct = 3.93E-6;
var entry = 3.93E-2; //really comes from an input box.
if (!(entry / correct)%10) {
alert ("power of ten error");
}
However, this doesn't work as error/correct doesn't work for large/small numbers.
How can I fix this?
Live code at: http://bradshawenterprises.com/test.html