I have a bootstrap/jquery/javascript app that allows the person to log in then they are taken to a table of contents page where they can click a link in order to play a video. I have code on the table of contents page that gives them a personalized message.
<script type="text/javascript" language="javascript">
function WelcomeMsg() {
// Retrieve the users name.
var name = localStorage.getItem('name');
if (name != "undefined" && name != "null") {
document.getElementById('welcomeMessage').innerHTML = "Welcome " + name + " !" + " ";
} else
document.getElementById('welcomeMessage').innerHTML = "Hello!";
}
</script>
The code works well when someone logs in properly but if someone doesn't log in and skips directly to the tableOfContents.html page then I want the message to say simply "Hello." Unfortunately right now in that situation it says "Welcome null." Can someone tell me what I'm doing wrong? Thank you.