2017-02-21 101 views
0

这是我的代码;是否有可能获得返回结果的变量?

var notificar = prompt("qual é seu nome ?"); 

function teste(name) { 
    // return name +" Voce é o aluno"; 
    var teste = return false; 
} 

if (teste == false) { 
    alert("Olá amiguinhos da tv (teste == false)"); 
} else { 
    alert(" Ola amiguinhas da tv ??? (teste == true)"); 
} 

alert(teste(notificar)); 

我想获取回报的布尔值,这样我可以做我的病情结构

+0

应该在函数内部测试什么? –

回答

0

在这条线var teste = return false;

它会给Uncaught SyntaxError: Unexpected token return错误。

而且,即使将其更改为return false;下面的代码将无法执行,因为你报税表的执行。

所以,我认为唯一的解决办法只是分配给falsevar teste

var teste = false;

1

你需要像你想这样做的方法全局变量工作。 而结构必须是正确的例子;

var notificar = prompt("qual é seu nome ?"); 
 

 
// Declare global variable here 
 
var teste; 
 

 
function teste(name) { 
 
    // return name +" Voce é o aluno"; 
 
    // Set the global variable to (in this ase) false 
 
    teste = false; 
 
} 
 

 
// First run the function to set the boolean 
 
teste(notificar) 
 

 
// Than do the check what teste is 
 

 
if (teste == false) { 
 
    alert("Olá amiguinhos da tv "); 
 
} else { 
 
    alert(" Ola amiguinhas da tv ???"); 
 
}

0

其实,如果你尝试执行你的代码,你会得到一个语法错误。当你想检索您的函数返回,你可以执行它和属性约变量的值,就像这样:

var notificar = prompt("qual é seu nome ?"); 

function fnTeste(name) { 
    return false; 
} 

var teste = fnTeste(notificar); // Here is the attribuition 

if (teste == false) { 
    alert("Olá amiguinhos da tv "); 
} else { 
    alert(" Ola amiguinhas da tv ???"); 
} 

alert(fnTeste(notificar)); 

注意变量“阿泰斯特”使用功能“fnTeste”的价值,你想要(它们不能具有相同的名称,因为它们用于不同的目的)。

我希望它能帮助!

0

可以直接调用使用功能“泰斯特(notificar);”并将结果存储在声明的'var'中...

var notificar = prompt("qual é seu nome ?"); 
function teste(name) { 
    // return name +" Voce é o aluno"; 
    return false; //returns the return value at calling function 
} 
var teste1=teste(notificar); 
if (teste1== false) { 
    alert("Olá amiguinhos da tv (teste == false)"); 
} 
else { 
    alert(" Ola amiguinhas da tv ??? (teste == true)"); 
} 
alert(teste(notificar)); 
相关问题