I am creating a maths game with Javascript by randomly generating two numbers between 1 and 12 and carrying out some mathematics on the two (randomly putting one of: +,-,*,/). Divide proves a problem as obvously two numbers divided can result in awkward answers, recurring 3's for example. Does anyone know how I can check for a decimal point in an answer and if so generate a new equation? Many thanks, Chris
You can use the % operator. if you have 2 values a and b, a%b gives you the remainder, like 4%3 = 1. So in your case, that would be something like: if(a%b==0){ // do something }else{ // generate new equation } Code (markup):