Js,功能不起作用

时间:2016-07-31 17:29:19

标签: javascript

`var y = 0 ;
var x = 0;
function atm(num1, num2){
console.log((num1 - num2));
return num1 - num2 ;
}
var items =[1,2,3,4,5,6,7,8,9,10];
function vm(y, x){
if( atm(y , items[x]) < 0  ){
    result = "U Do not have enough money to pay";
}
else if ( atm(y , items[x]) === 0  );{
    result = "Ur money just matches the required paying fee";
}
if ( atm(y , items[x]) > 0  );{
    result="U will reserve atm(y, items[x]) as a remainder";
}
}

vm(2, 3);`

**错误是它给了我3个答案,你可以看到: \\ -2

&#34; U没有足够的钱支付&#34;

&#34;你的钱只需支付所需的费用&#34;

-2

&#34; U将保留atm(y,items [x])作为余数&#34; \\

\\ 也是第3个结果&#34; result =&#34; U将保留atm(y,items [x])作为余数&#34; &#34;不会显示剩余部分

&#34; y支付你持有的金额&#34;

&#34; x转到数组&#34;

中的项目数

vm是自动售货机,它应该做的是显示这些的答案

1-你没有足够的钱支付

2- Ur钱只需支付所需的费用

3-是他有更多钱,他会保留&#34; y - items [x]&#34;作为剩余部分

当你收到我的错误时请写下错误和完整代码,有时候我会变得很难,我还是新的......

1 个答案:

答案 0 :(得分:0)

我认为这是对的。

var y = 0;
var x = 0;
var items = [1,2,3,4,5,6,7,8,9,10];

function atm(num1, num2){
  return num1 - num2;
}


function vm(y, x) {
  if( atm(y, items[x]) < 0  ) {
      result = "You Do not have enough money to pay";
  }
  else if ( atm(y, items[x]) === 0  ) {
      result = "Ur money just matches the required paying fee";
  }
  else {
      result = "U will reserve " + atm(y, items[x]) +" as a remainder";
  }
  return result;
}

vm(2, 3)
// "You Do not have enough money to pay"