Conditional statements :
1/Check a number is even or odd :
2/ Find the largest between two numbers :
3/ Find the largest of three number :
// program using switch statement
let a = 2;
switch (a) {
case 1:
a = 'one';
break;
case 2:
a = 'two';
break;
default:
a = 'not found';
break;
}
// output : twolet a = 1;
switch (a) {
case "1":
a = 1;
break;
case 1:
a = 'one';
break;
case 2:
a = 'two';
break;
default:
a = 'not found';
break;
}
// output : one
4/ Simple calculator with if else :
5/ Simple calculator with switch :
Loops :
1/ Print the summation of numbers between 0 and 10 :
2/ Write a code to print numbers from 1 to 10 :
3/ print only even numbers between 0 and 20
4/ simple while loop :
all in one example :
References :
Thanks for reading, and feel free to ask any question about javascript or about this series and i appreciate any feedback to improve My content.
find me on twitter, github and my portfolio.