-4
var name = prompt("What's your name writer?");
var firstletr = name.slice(0,1).toUpperCase(); 
var remaining = name.slice(1,name.length).toLowerCase();
name = (firstletr+remaining+"'s journal"); 

if (name!=null || name!="") 
{ 
  document.getElementById('username').innerHTML= true; 
} 

else { 
  document.getElementById('username').innerHTML= false; 
}
Michelangelo
  • 5,888
  • 5
  • 31
  • 50
Mudit Gulgulia
  • 1,131
  • 7
  • 21
  • You might want to give some type of description of the problem. Maybe tell what you have tried etc. In this case though, you should try move the if/else to above the `name = (first...` snippet and not set innerHTML to false, but to the text that the innerHTML should have. – Jite Aug 10 '19 at 20:33
  • Possible duplicate of [Javascript prompt() - cancel button to terminate the function](https://stackoverflow.com/questions/12864582/javascript-prompt-cancel-button-to-terminate-the-function) – Emile Bergeron Aug 11 '19 at 03:51

1 Answers1

3

From the Mozilla Javascript docs :

When the user clicks the OK button, text entered in the input field is returned. If the user clicks OK without entering any text, an empty string is returned. If the user clicks the Cancel button, this function returns null.

That means if name is null then you know the user clicked Cancel. If it is any other value (including the empty string) then they clicked OK.

Cameron Skinner
  • 51,692
  • 2
  • 65
  • 86