javascriptプロンプトの戻り値の型は常にオブジェクトですか?
function check_color(){
\t
\t color_input = prompt("I am thinking of one of these colors: \n\n"+
\t \t \t \t \t \t "blue, cyan, gold, gray, magenta, orange, red, white, yellow \n\n"+
\t \t \t \t \t \t "What color am I thinking of?");
\t
\t if(color_input != null || color_input != undefined){
\t
\t \t if(typeof (color_input) != 'string') {
\t \t \t alert("This is not any color. \n\n"+
\t \t \t "Please enter color in text format");
\t \t \t return false;
\t }
\t
\t \t if(colors.indexOf(color_input) < 0){
\t \t \t alert("Sorry, i don't recognize your color. \n\n"+
\t \t \t "Please try again");
\t \t \t return false;
\t }
}
else{
\t alert("Please enter some input");
\t return false;
}
}
なぜ常に最初-場合は、このコードを実行しようとすると、ブロックが実行されていますか?誰かがexpalinしてくださいできますか?
これはOR条件の仕組みです。 'color_input!= null || color_input!= undefined'は 'color_input!= null && color_input!= undefined'です。 – Tushar
@Tusharそれは条件ではありませんか?もし私が狂気ならCorect ng。 – izengod
&& = and、|| =または –