-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlv6-sistema-de-descuentos.ts
More file actions
38 lines (32 loc) · 1.06 KB
/
lv6-sistema-de-descuentos.ts
File metadata and controls
38 lines (32 loc) · 1.06 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
/* Según el tipo de cliente (nuevo, frecuente, vip) y el monto de compra, asigna un descuento distinto.
*/
enum Cliente{
Nuevo = "nuevo",
Frecuente = "frecuente",
Vip = "vip"
}
function descuento(cliente: Cliente,monto: string): string{
let montoNum: number = Number(monto);
let porcentaje: number;
let mensajeCliente: string;
switch (cliente){
case Cliente.Nuevo :
porcentaje = montoNum >= 1000?0.25:0.10;
mensajeCliente = "nuevo cliente";
break;
case Cliente.Frecuente :
porcentaje = montoNum >= 1000?0.40:0.15;
mensajeCliente = "cliente frecuente";
break;
case Cliente.Vip :
porcentaje = montoNum >= 1000?0.50:0.20;
mensajeCliente = "cliente VIP";
break;
default:
return "El cliente no pertenece a la tienda";
}
let montoFinal: number = montoNum - montoNum*porcentaje;
let porcentajeTexto: string = String(porcentaje*100);
return `Descuento del ${porcentajeTexto}% por ser ${mensajeCliente}, monto final: ${montoFinal}`;
}
console.log(descuento(Cliente.Frecuente,"1500"));