如何在JavaScript中显示+和 - 登录警告框

时间:2017-09-03 18:14:07

标签: javascript-events

There are three variables as follows
var a=1;
var b=-2; 
var c=4;
If I performed following options
var Res=a*b*c;
Or
var Res=a+b+c;

然后,如果结果是-ve值显示 - 在警告框中,如果结果是+ ve    值显示+在警告框中

1 个答案:

答案 0 :(得分:0)



var a=1;
var b=-2; 
var c=4;

var Res1=a*b*c;

var Res2=a+b+c;

function alertPlusOrMinus(n) {
    if( n < 0 ){
        alert('-');
    } else {
        alert('+');
    }
}

alertPlusOrMinus( Res1 );
alertPlusOrMinus( Res2 );
&#13;
&#13;
&#13;