2016-04-28 26 views

答えて

2

我々はをキャンセルをクリックすると、(例外が発生します!)プロンプトがnullを返し、1はnulltoLowerCaseを適用することはできません

他のすべての条件前の状態answer===nullを追加し、returnにはの実行を停止function

function funcPrompt() { 
 
    var answer = prompt("Are you a photographer?", "Yes/No"); 
 
    if (answer === null || answer === "") { 
 
    alert('Please enter an answer.'); 
 
    funcPrompt(); 
 
    return; 
 
    } 
 
    answer = answer.toLowerCase(); 
 
    if (answer == "yes") { 
 
    alert('Excellent! See our links above and below to see more work and find contact info!'); 
 
    } else if (answer == "no") { 
 
    alert('That is okay! See our links above and below to learn more!'); 
 
    } else { 
 
    alert('Sorry, that answer is not an option'); 
 
    funcPrompt(); 
 
    } 
 
} 
 
funcPrompt();

あなたのケースで
0

は、より良いプロンプト

function funcConfirm() { 
 
    var answer = confirm("Are you a photographer?"); 
 

 
    if (answer === true) { 
 
    alert('Excellent! See our links above and below to see more work and find contact info!'); 
 
    } else { 
 
    alert('That is okay! See our links above and below to learn more!'); 
 
    } 
 
} 
 

 
funcConfirm();

の代わりに確認を使用します
関連する問題