Search code examples
javascripthtmlprompt

Question: How to do so that (null) does not appear in (document.write)


How can I change my code so that if the user presses on cancel the following code will write document.write("#DELETE") or simply leave an empty space?

<!DOCTYPE html>
<html>
<body>
<script language="JavaScript">
var a = prompt("Put a text");

if (a === null || !a) {
    document.write("");
} else {
   document.write( "Your Text is: " + a );
}
</script>
</body>
</html>

Solution

  • var radiuuss = prompt("Please set the radius");
    document.write("Press 1 to put the code or press 2 to clear section");   
    if (radiuuss === null) {
        document.write("#DELETE");
    } else {
       // document write a message with the value of the radiuuss.
    }