Write a programme using loop for star pattern;
<html>
<head><title>javascript</title>
<script>
function switch(){
let a;
a=2; // if we will give the value of a=1; then all cases will display , if we give the value of a=3; then first two cases will display and if a=4; then first case will display
switch(a){
case 1:
document.write("hello"+"<br>");
case 2:
document.write("javascript"+"<br>");
case 3:
document.write("HTML"+"<br>");
case 4:
document.write("CSS");
}
}
document.getElementById("demo").innerHTML=switch();
</script>
</head>
<body>
<p id="demo"></p>
</body>
</html>
output:-
Hello
javascript
HTML
Write a programme using loop for downward star pattern;
<html>
<head><title>javascript</title>
<script>
function switch(){
let a;
a=1;
switch(a){
case 1:
document.write("hello"+"<br>");
case 2:
document.write("javascript"+"<br>");
break; // where we will write break case will end at it
case 3:
document.write("HTML"+"<br>");
case 4:
document.write("CSS");
}
}
document.getElementById("demo").innerHTML=switch();
</script>
</head>
<body>
<p id="demo"></p>
</body>
</html>
hello
javascript