filmov
tv
Conditional statements in javascript

Показать описание
Link for all dot net and sql server video tutorial playlists
Link for slides, code samples and text version of the video
Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.
JavaScript code is executed in a linear fashion from the first line to the last line. If for some reason you want to interrupt this flow and execute certain statements, only, if certain condition is met, then we use conditional statements.
JavaScript has the following conditional statements
if
if else
if else if else
switch
ternary operator - shortcut for an if...else statement
If example
var userInput = Number(prompt("Please enter a number", ""));
if (userInput == 1)
{
alert("You number is One");
}
if (userInput == 2)
{
alert("You number is Two");
}
if (userInput == 3)
{
alert("Your number is Three");
}
if(userInput != 1 && userInput != 2 && userInput != 3)
{
alert("Your number is not between 1 and 3");
}
If else if example
var userInput = Number(prompt("Please enter a number", ""));
if (userInput == 1)
{
alert("You number is One");
}
else if (userInput == 2)
{
alert("You number is Two");
}
else if (userInput == 3)
{
alert("Your number is Three");
}
else
{
alert("Your number is not between 1 and 3");
}
Link for slides, code samples and text version of the video
Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.
JavaScript code is executed in a linear fashion from the first line to the last line. If for some reason you want to interrupt this flow and execute certain statements, only, if certain condition is met, then we use conditional statements.
JavaScript has the following conditional statements
if
if else
if else if else
switch
ternary operator - shortcut for an if...else statement
If example
var userInput = Number(prompt("Please enter a number", ""));
if (userInput == 1)
{
alert("You number is One");
}
if (userInput == 2)
{
alert("You number is Two");
}
if (userInput == 3)
{
alert("Your number is Three");
}
if(userInput != 1 && userInput != 2 && userInput != 3)
{
alert("Your number is not between 1 and 3");
}
If else if example
var userInput = Number(prompt("Please enter a number", ""));
if (userInput == 1)
{
alert("You number is One");
}
else if (userInput == 2)
{
alert("You number is Two");
}
else if (userInput == 3)
{
alert("Your number is Three");
}
else
{
alert("Your number is not between 1 and 3");
}
Комментарии