Skip to content

Commit 6dcf764

Browse files
authored
Merge pull request mouredev#2343 from AChapeton/main
#11 - TypeScript & JavaScript
2 parents c7f15a5 + 8e3c808 commit 6dcf764

File tree

3 files changed

+181
-0
lines changed

3 files changed

+181
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# https://www.python.org/
2+
3+
# Comentario de una linea
4+
"""
5+
Comentario
6+
en varias
7+
lineas
8+
"""
9+
10+
#Crear variables
11+
x = 'Nombre'
12+
y = 5
13+
14+
#En Python no existe el concepto de constantes, pero en la cominidad se representan declarando una variables en mayusculas
15+
PI = 3.1416
16+
17+
#Tipos de datos primitivos
18+
19+
#String
20+
my_string = "Hello"
21+
22+
#Enteros
23+
my_number = 10
24+
my_float = 2.5
25+
26+
#Booleanos
27+
my_boolean = True
28+
other_boolean = False
29+
30+
#None - Ausencia de valor
31+
my_none = None
32+
33+
name = 'Python'
34+
print('¡Hola, ' + name + "!")
35+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
var fs = require('fs');
4+
var readlineSync = require('readline-sync');
5+
//writeFile permite escribir en un fichero, y tambien lo crea si este aun no existe
6+
fs.writeFile('achapeton.txt', "\n - Nombre: Andres Chapeton\n - Edad: 26\n - Lenguaje favorito: TypeScript\n ", function (error) {
7+
if (error)
8+
throw error;
9+
console.log('File created');
10+
});
11+
//Leer contenido del fichero
12+
fs.readFile('achapeton.txt', function (error, data) {
13+
if (error)
14+
throw error;
15+
console.log(data.toString());
16+
});
17+
//Eliminar un fichero
18+
fs.unlink('achapeton.txt', function (error) {
19+
if (error)
20+
throw error;
21+
console.log('File deleted');
22+
});
23+
// DIFICULTAD EXTRA
24+
var guardarVenta = function () {
25+
var nombreProducto = readlineSync.question('Nombre del producto ');
26+
var cantidadVendida = readlineSync.question('Cantidad vendida: ');
27+
var precioTotal = readlineSync.question('Precio: ');
28+
fs.appendFile('ventas.txt', "".concat(nombreProducto, ", ").concat(cantidadVendida, ", $").concat(precioTotal, "]"), function (error) {
29+
if (error)
30+
throw error;
31+
});
32+
};
33+
var listarVentas = function () {
34+
fs.readFile('ventas.txt', function (error, data) {
35+
if (error)
36+
throw error;
37+
console.log(data.toString());
38+
});
39+
};
40+
var gestionarVentas = function () {
41+
var option = '';
42+
var menu = 'MENU: \n 1. Agregar nueva venta \n 2. Listar ventas \n 3. Salir \n Escoger una opcion: ';
43+
while (option !== '3') {
44+
option = readlineSync.question(menu);
45+
switch (option) {
46+
case '1':
47+
guardarVenta();
48+
break;
49+
case '2':
50+
listarVentas();
51+
break;
52+
case '3':
53+
fs.unlink('ventas.txt', function (error) {
54+
if (error)
55+
throw error;
56+
console.log('Fichero eliminado');
57+
});
58+
break;
59+
default:
60+
console.log('Opcion no valida. Intentar de nuevo.');
61+
break;
62+
}
63+
}
64+
};
65+
gestionarVentas();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { error } from "console"
2+
3+
const fs = require('fs')
4+
const readlineSync = require('readline-sync');
5+
6+
//writeFile permite escribir en un fichero, y tambien lo crea si este aun no existe
7+
fs.writeFile(
8+
'achapeton.txt',
9+
`
10+
- Nombre: Andres Chapeton
11+
- Edad: 26
12+
- Lenguaje favorito: TypeScript
13+
`,
14+
(error: NodeJS.ErrnoException | null) => {
15+
if(error) throw error
16+
console.log('File created')
17+
})
18+
19+
//Leer contenido del fichero
20+
fs.readFile('achapeton.txt', (error: NodeJS.ErrnoException | null, data: any) => {
21+
if(error) throw error
22+
console.log(data.toString())
23+
})
24+
25+
//Eliminar un fichero
26+
fs.unlink('achapeton.txt', (error: NodeJS.ErrnoException | null) => {
27+
if(error) throw error
28+
console.log('File deleted')
29+
})
30+
31+
32+
33+
// DIFICULTAD EXTRA
34+
35+
const guardarVenta = () => {
36+
const nombreProducto: string = readlineSync.question('Nombre del producto ');
37+
const cantidadVendida: number = readlineSync.question('Cantidad vendida: ');
38+
const precioTotal: string = readlineSync.question('Precio: ');
39+
fs.appendFile(
40+
'ventas.txt',
41+
`${nombreProducto}, ${cantidadVendida}, $${precioTotal}]`
42+
,
43+
(error: NodeJS.ErrnoException | null) => {
44+
if(error) throw error
45+
})
46+
}
47+
const listarVentas = () => {
48+
fs.readFile('ventas.txt', (error: NodeJS.ErrnoException | null, data: any) => {
49+
if(error) throw error
50+
console.log(data.toString())
51+
})
52+
}
53+
54+
const gestionarVentas = () => {
55+
let option: string | null = ''
56+
const menu: string = 'MENU: \n 1. Agregar nueva venta \n 2. Listar ventas \n 3. Salir \n Escoger una opcion: '
57+
58+
while (option !== '3') {
59+
option = readlineSync.question(menu)
60+
61+
switch (option) {
62+
case '1':
63+
guardarVenta()
64+
break;
65+
case '2':
66+
listarVentas()
67+
break;
68+
case '3':
69+
fs.unlink('ventas.txt', (error: NodeJS.ErrnoException | null) => {
70+
if(error) throw error
71+
console.log('Fichero eliminado')
72+
})
73+
break;
74+
default:
75+
console.log('Opcion no valida. Intentar de nuevo.')
76+
break;
77+
}
78+
}
79+
}
80+
81+
gestionarVentas()

0 commit comments

Comments
 (0)