![]() In so-called ‘Western Culture’ we love to celebrate the weekend, so let’s create a simple script to help people celebrate. A Working Example of JavaScript Conditional Statements they try to press ‘OK’ without putting something in) or if they press ‘CANCEL’ then you can use an if() statement to catch that. If they put something in then ask_the_user is given that value. You can then assign what they put in to a variable.Īsk_the_user = prompt('What day is it today?') JavaScript Prompt in Google Chrome Aside: A Simple Prompt for Input From the UserĪs this doesn’t really warrent a whole lesson, JavaScript gives you a really easy way to ask for user for text input – via the prompt() function. You can use AND ( &) and OR ( ||) within each nested statement as well. With our ‘TRUE/FALSE’ outcomes we want to know: If your condition is not met then we need to use an else statement and see what happens. The code does nothing and the user does not know that nothing has happened! When writing the functions in JavaScript you must always keep the user informed about what’s going on. With the two code snippets above, if the condition is not met, the nothing happens. But it’s important you know what’s going on behind your if() statements. This does not need to be programmed in, as it is handled automatically. If a conditional is not met, then the statement returns False. If a condition is met then the conditional statement returns True. In programming terms this is called a Boolean. ![]() This is in the form of ‘True or False’ (alternatively 1 or 0 respectively). JavaScript Conditional Statements give a ‘hidden’ value to determine if the condition is met. Understanding the Response of a Conditional Statement Then if what_day_is_it is not “Friday” we output a message. ![]() So this time what_day_is_it is set to ‘Thursday’.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |