![]() ![]() the action to perform once the condition is met.A conditional statement really has only two parts: ![]() The best part? You aren’t limited to a single condition, you can repeat this approach for any number of conditions - if the user prefers German, display the page in German, if they prefer Russian, display it in Russian.Īn interesting thing about conditional statements is how simple they are. ~A conditional statement tells JavaScript how it should behave when a certain condition is met~.įor example, if a user visits your website and their preferred language is French, you could use a JavaScript conditional statement to determine the user’s preferred language is French, and then display the content of your website in French to them. If a condition is met, then the code will continue running until the condition becomes false. This ability is most useful to developers when they want to perform tasks repeatedly without having to repeat themselves. If a condition is met the code should do something, but in a case where the conditions are not met something else should happen. These are the digital equivalents of the decisions we make where our code does something different depending on whether something is true or false.Ĭonditional statements therefore are used for controlling how a piece of code should work. In this tutorial, I will cover what is known as conditional statements. This especially applies to everything our computer does. when you’ve decided on your favourite jeans, you’d probably need to match that with a nice shirt.īroadly speaking, every decision you and I make can be modelled as a series of true and false statements. ![]() for instance, whether you want to wear your favourite jeans or just joggers. The answer to that question determines your next step. ![]() Once the alarm goes off, you either decide to get up or hit the snooze button and head back to sleep.Īt each stage of making a decision, you ask yourself a question that can be answered as true or false. Everyday you wake up, you make a decision. ![]()
0 Comments
Leave a Reply. |