Trying to compare cancel from prompt dialog not working
-
Below I have the code I am working with. The if statement in the script is not working. What I want to do is catch the value of the prompt dialog box if the user clicks the cancel buttom and exit the script if that is the case. I have tried: if (color=="null") if (color==="null") if (color=='null') if (color==='null') if (color==null) if (color===null) and none of them work. I can make the script work if I do: if(color!=null) and modify the logical processing but I am trying to make work with the equals comparison. If I comment out the if conditional statement, it works fine. Any help is greatly appreciated. Thank you.
<!--
var color = prompt("Enter a color","Enter red, white, or blue.")function colorTest(){
//\*\*\*\*\*\*\*\*\*\* if statement not working properly if(color === null){ break; } switch(color){ case "red": alert("You have entered the color ' red '"); break; case "white": alert("You have entered the color ' white '"); break; case("blue"): alert("You have entered the color ' blue '"); break; default: alert("You did not enter a valid color"); }
}//end function
//-->
-
Below I have the code I am working with. The if statement in the script is not working. What I want to do is catch the value of the prompt dialog box if the user clicks the cancel buttom and exit the script if that is the case. I have tried: if (color=="null") if (color==="null") if (color=='null') if (color==='null') if (color==null) if (color===null) and none of them work. I can make the script work if I do: if(color!=null) and modify the logical processing but I am trying to make work with the equals comparison. If I comment out the if conditional statement, it works fine. Any help is greatly appreciated. Thank you.
<!--
var color = prompt("Enter a color","Enter red, white, or blue.")function colorTest(){
//\*\*\*\*\*\*\*\*\*\* if statement not working properly if(color === null){ break; } switch(color){ case "red": alert("You have entered the color ' red '"); break; case "white": alert("You have entered the color ' white '"); break; case("blue"): alert("You have entered the color ' blue '"); break; default: alert("You did not enter a valid color"); }
}//end function
//-->
That
break
inside theif
does nothing...only jumps out of the if and continues to theswitch
! You meantreturn
I think...I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
-
Below I have the code I am working with. The if statement in the script is not working. What I want to do is catch the value of the prompt dialog box if the user clicks the cancel buttom and exit the script if that is the case. I have tried: if (color=="null") if (color==="null") if (color=='null') if (color==='null') if (color==null) if (color===null) and none of them work. I can make the script work if I do: if(color!=null) and modify the logical processing but I am trying to make work with the equals comparison. If I comment out the if conditional statement, it works fine. Any help is greatly appreciated. Thank you.
<!--
var color = prompt("Enter a color","Enter red, white, or blue.")function colorTest(){
//\*\*\*\*\*\*\*\*\*\* if statement not working properly if(color === null){ break; } switch(color){ case "red": alert("You have entered the color ' red '"); break; case "white": alert("You have entered the color ' white '"); break; case("blue"): alert("You have entered the color ' blue '"); break; default: alert("You did not enter a valid color"); }
}//end function
//-->
-
Below I have the code I am working with. The if statement in the script is not working. What I want to do is catch the value of the prompt dialog box if the user clicks the cancel buttom and exit the script if that is the case. I have tried: if (color=="null") if (color==="null") if (color=='null') if (color==='null') if (color==null) if (color===null) and none of them work. I can make the script work if I do: if(color!=null) and modify the logical processing but I am trying to make work with the equals comparison. If I comment out the if conditional statement, it works fine. Any help is greatly appreciated. Thank you.
<!--
var color = prompt("Enter a color","Enter red, white, or blue.")function colorTest(){
//\*\*\*\*\*\*\*\*\*\* if statement not working properly if(color === null){ break; } switch(color){ case "red": alert("You have entered the color ' red '"); break; case "white": alert("You have entered the color ' white '"); break; case("blue"): alert("You have entered the color ' blue '"); break; default: alert("You did not enter a valid color"); }
}//end function
//-->