The 'else' Statement in JavaScript

If we'd like to give other users (not Jim or Tom) a message, we can use the else statement:

if(username == 'Jim') {
    alert('Welcome Jim')
} else if(username = 'Tom') {
    alert('Sorry Tom, you are not authorized to view this page.')
} else {
    alert('Sorry, you are not Jim or Tom.')
}

Next: Commenting in JavaScript

Comments

Leave a comment

What color are green eyes? (spam prevention)
Submit
Code under MIT License unless otherwise indicated.
© 2020, Downranked, LLC.