Script Experiment

Factoring Quadratics

var A=[-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,+1,+2,+3,+4,+5,+6,+7,+8,+9,+10,-11,11,-12,+12,-13,+13,-14,+14,-15,+15]
var p=0
var w=0
while(p!=10)
{
  console.log("Factor the following:")
  let b=A[Math.floor(Math.random()*A.length)]
  let c = A[Math.floor(Math.random()*A.length)]
  d=-1*b+-1*c
  e=b*c
  if(d>=0)
  {
    if(e>=0)
    {
      console.log("x^2+"+d+"x"+"+"+e)
      console.log("")
    }
    else
    {
      console.log("x^2+"+d+"x"+e)
      console.log("")
    }
  }
  else
  {
    if(e>=0)
    {
      console.log("x^2"+d+"x"+"+"+e)
      console.log("")
    }
    else{
      console.log("x^2"+d+"x"+e)
      console.log("")
    }
  }
  var m=prompt("Root 1?")
  var n=prompt("Root 2?")
  if(m==b&&n==c)
  {
    console.log("Correct")
    console.log("")
    p=p+1
  }
  else
  {
    if(m==c&&n==b)
    {
      console.log("Correct")
      console.log("")
      p=p+1
    }
    else
    {
      console.log("Incorrect")
      console.log("")
      w=w+1
    }
  }
}
console.log("You got "+w+" questions wrong")