-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlv4-validacion-de-rango-de-edad.ts
More file actions
47 lines (38 loc) · 1.01 KB
/
lv4-validacion-de-rango-de-edad.ts
File metadata and controls
47 lines (38 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/* Según la edad, clasifica: niño (0-12), adolescente (13-17), adulto (18-59), adulto mayor (60+). */
interface Personarandom{
nombre:string;
edad:number;
}
let userUno: Personarandom ={
nombre:"pedro pascal",
edad:23
}
let userDos: Personarandom = {
nombre:"barry allen",
edad:15
}
let userTres: Personarandom = {
nombre:"bruce wayne",
edad:62
}
let userCuatro: Personarandom = {
nombre:"dexter",
edad:11
}
function censo(nombre: string,edad: number): string{
if((edad >= 0) && (edad <= 12)){
return `${nombre} es un niño`;
}else if((edad > 12) && (edad <= 17)){
return `${nombre} es un adolescente`;
}else if((edad >=18) && (edad < 60)){
return `${nombre} es un adulto`;
}else if(edad > 60){
return `${nombre} es un adulto mayor`;
}else{
return "edad incorrecta";
}
}
console.log(censo(userUno.nombre,userUno.edad));
console.log(censo(userDos.nombre,userDos.edad));
console.log(censo(userTres.nombre,userTres.edad));
console.log(censo(userCuatro.nombre,userCuatro.edad));