Skip to content

Commit 3e4ecc2

Browse files
committed
practica de condicionales switch
1 parent 53b68fb commit 3e4ecc2

1 file changed

Lines changed: 61 additions & 0 deletions

File tree

sentencia_switch.html

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Sentencia switch en JavaScript</title>
6+
</head>
7+
<body>
8+
<script>
9+
/**
10+
* SIWTCH:
11+
* - Se utiliza para hacer diferentes acciones basadas en diferentes condiciones.
12+
* - La condición se evalúa una única vez.
13+
* - Si hay alguna coincidencia con algún valor se ejecuta el bloque de código correspondiente.
14+
*
15+
* SINTAXIS:
16+
* switch (<expresión>) {
17+
* case valor_1:
18+
* // Instrucciones para el valor_1
19+
* break;
20+
* case valor_n:
21+
* // Instrucciones para el valor_n
22+
* break;
23+
* default:
24+
* // Instrucciones si no se cumple ninguna condición
25+
* break;
26+
* }
27+
**/
28+
var nota = 3;
29+
var mensaje = "";
30+
31+
switch (nota) {
32+
case 0:
33+
case 1:
34+
case 2:
35+
case 3:
36+
case 4:
37+
mensaje = "Suspenso";
38+
break;
39+
case 5:
40+
mensaje = "Suficiente";
41+
break;
42+
case 6:
43+
mensaje = "Bien";
44+
break;
45+
case 7:
46+
case 8:
47+
mensaje = "Notable";
48+
break;
49+
case 9:
50+
case 10:
51+
mensaje = "Sobresaliente";
52+
break;
53+
default:
54+
mensaje = "El valor no es valido";
55+
break;
56+
}
57+
58+
alert(mensaje);
59+
</script>
60+
</body>
61+
</html>

0 commit comments

Comments
 (0)