在“警报”框中显示逻辑操作的结果

时间:2015-04-11 08:37:29

标签: javascript html

有人能告诉我我做错了吗?

以下是我在.js文件中的Javascript代码:

function call_alert()
{
    alert (result);
}

var a = true; , b = false;

var test1 = (a && a);

var test2 = (a && b);

var test3 = (b && b);

var result = "Are they true? \n";

result += "1:" +test1+;

为简单起见,我没有包含变量test2和test3。

我的HTML只是标准<body onload ="call_alert()">

2 个答案:

答案 0 :(得分:0)

尝试这样可以正常工作

function call_alert()
{
    alert (result);
}

var a = true; 
var b = false;

var test1 = (a && a);

var test2 = (a && b);

var test3 = (b && b);

var result = "Are they true? \n";

result += "1:" +test1;

答案 1 :(得分:0)

不太确定你想要做什么,但我会试一试。

var a = true, b = false;

function callAlert() {
   alert (result);
}

var test1 = (a && a);
var test2 = (a && b);
var test3 = (b && b);

var result = "Are they true? y" + "/" + "n";

result += " 1 " + test1;