![javascript,tutorial,code prime,if else if statement,javascript if statement multiple conditions,if statement syntax,if else statement syntax,how to write an if statement in javascript if i=5,javascript conditionals,if else condition in html code,if else statement in java,javascript tutorial for beginners,javascript tutorial,types of conditional statements in javascript,How many conditional statements,if,else,else-if,if statement in java, codeprime, coding tutorial, how to learn coding easy way to learn coding](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMrPB3njoiN9U5iZsz7yKHLhTcdn0pSpixdjI5tgvrtU5VDDDSslP3EsbPvdiYHqVd0Yc0iHiBs9TffAe1DUdV35Pwxd4IGcZzkEo5Kpyfy_MF-e849mc0nADisjZkxXB4bxXEgEX-Njy1tBr5D5zBbgbw3MookKM9ptiqBHMz_uYwtHdO4lm8GWN-1g/s1600/IF%20ELSE%20ELSE%20IF.png)
Hi dear welcome to "CodePrime" Blog . In this post you are going to learn How to use If, Else, and Else-if conditional statement in javascript. First Creat A index.html file Copy This HTML CODE and pest it one your code editor. 2ndly creat if-else-if.js file Then Copy The JS CODE and pest it. Next connect if-else-if.js file with your index.html then open the index.html file with your browser.
HTML CODE
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="/js/if-else-if.js"></script>
<title>javascript</title>
</head>
<body>
<h2>Javascript Tutorial</h2>
<h3>By Codeprime</h3>
</body>
</html>
JAVASCRIPT CODE
let numbers=[];
numbers=[1,2,1,2,3,1,2];
if(numbers[0]==numbers[2]) {
console.log('its correct');
};
// if else example
if(numbers[0]==numbers[3]) {
console.log('its correct');
} else{
console.log(' its wrong');
}
//else-if example
if(numbers[0]==numbers[3]) {
console.log('1st block');
} else if (numbers[1]==numbers[3]) {
console.log(' 2nd block');
} else {
console.log(' 3rd block');
}
0 Comments