2017-02-21 20 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)); 

私はそれがUncaught SyntaxError: Unexpected token returnエラーになります。このラインvar teste = return false;

で私の条件構造

+0

関数内でテストする必要があるものはありますか? –

答えて

0

を行うことができるようにリターンのブール値を取得したいと思います。

return false;に変更しても、フォームを実行して戻ってくるので、以下のコードは実行されません。

だから、私は唯一の解決策は、ちょうどあなたがこれをやりたい道のようなグローバルVARで作業する必要がfalsevar teste = false;すなわち

var teste

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

、あなたのコードを実行しようとした場合、実際には、構文エラーを取得します。変数「精巣は」あなたと「fnTeste」関数の値を使用していること

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)); 

注意:あなたはあなたの関数は、あなたがそれを実行し、ちょうどそのような変数をatributeでき返す値を取得するよう(彼らは別の目的のために使用されるので、同じ名前を持つことはできません)。

私はそれが助けてくれることを願っています!

0

「teste(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)); 
関連する問題