建立二次计算器程序,根本不对,也不是答案

时间:2019-02-07 07:31:28

标签: javascript quadratic code.org

我一直在学习二次方程式,并且一直在研究二次方程式。我决定制定一个程序来帮助我,因为我很无聊,而且我找不到错误所在。我正在使用code.org的游戏实验室

我尝试使用不同版本的平方和平方根,但无法弄清楚。

var a = prompt("What is A? ");
var b = prompt("What is B? ");
var c = prompt("What is C? ");
var x = prompt("What is your x value? ");
var verx = 0;
var very = 0;
var dop = prompt("Are you trying to find the root or the y of an x? ");

var y = 0;
var neg = 0;
function draw(){
  background("white");
  ans();

}
function ans(){
  if(dop == "root"){
    x = [-b+Math.sqrt(b^2-(4*a*c))]/2*a;
    neg = [-b-Math.sqrt(b^2-(4*a*c))]/2*a;
    text("The positive root is " + x, 100, 200);
    text("The negative root is " + neg, 100, 250);
  }
  if(dop == "y"){
    verx = (-b)/(2*a);
    very = ((a*Math.pow(verx, 2)) + (b *verx) + c);
    y = ((a*Math.pow(x, 2))+(b*x)+c);
    text("Vertex ( " + verx + ", " + very + " )", 100, 220);
    text("When x is " + x + " y is " + y, 100, 200);

  }
}  

我希望根和y值正确,但是唯一正确的是我的x顶点值。

0 个答案:

没有答案