File tree Expand file tree Collapse file tree 1 file changed +51
-0
lines changed
Roadmap/10 - EXCEPCIONES/javascript Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change
1
+ function dividir ( num1 , num2 ) {
2
+
3
+ if ( num2 === 0 ) {
4
+ throw new Error ( "No se puede dividir entre cero" ) ;
5
+ }
6
+ else {
7
+ return num1 / num2 ;
8
+ }
9
+
10
+ }
11
+ function Probar ( n1 , n2 ) {
12
+ try {
13
+ dividir ( n1 , n2 ) ;
14
+
15
+ } catch ( error ) {
16
+ console . log ( "Erro:" , error ) ;
17
+ }
18
+ finally {
19
+ console . log ( "Intente ingrsar un divisor distinto a 0" ) ;
20
+ }
21
+ }
22
+ Probar ( 10 , 0 ) ;
23
+ //Difucultad Extra
24
+
25
+ function exepciones ( us , pas ) {
26
+ if ( pas . length < 7 ) {
27
+ throw new Error ( "La contraseña debe de tener más de 7 caracteres" ) ;
28
+ }
29
+ else if ( typeof us !== 'string' ) {
30
+ throw new Error ( "Solo se permiten caracteres" ) ;
31
+ }
32
+ else if ( us === "" || pas === "" ) {
33
+ throw new Error ( "Campos vacios" ) ;
34
+ }
35
+
36
+ }
37
+ function Comprobar ( user , password ) {
38
+ try {
39
+ exepciones ( user , password ) ;
40
+ console . log ( "No ocurrienron exepciones" , user , password ) ;
41
+
42
+ } catch ( error ) {
43
+ confirm . log ( "Error" , error ) ;
44
+ }
45
+ finally {
46
+
47
+ console . log ( "Ingrese los datos nuevamente" ) ;
48
+ }
49
+
50
+
51
+ }
You can’t perform that action at this time.
0 commit comments