diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..7a73a41 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,2 @@ +{ +} \ No newline at end of file diff --git a/jmarquez/ejercicio01/index.js b/jmarquez/ejercicio01/index.js new file mode 100644 index 0000000..5ad5de1 --- /dev/null +++ b/jmarquez/ejercicio01/index.js @@ -0,0 +1,152 @@ +const players = { + 9: { + name: 'Bruno Fernandes', + jersey: 9, + goals: 5, + speed: 6, + assits: 9, + 'passing accuracy': 10, + 'defensive involvements': 3, + }, + 11: { + name: 'Rasmus Hojlund', + jersey: 11, + goals: 12, + speed: 8, + assits: 2, + 'passing accuracy': 6, + 'defensive involvements': 2, + }, + 5: { + name: 'Harry Maguire', + jersey: 5, + goals: 1, + speed: 5, + assits: 1, + 'passing accuracy': 7, + 'defensive involvements': 9, + }, + 17: { + name: 'Alejandro Garnacho', + jersey: 17, + goals: 8, + speed: 7, + assits: 8, + 'passing accuracy': 6, + 'defensive involvements': 0, + }, + 7: { + name: 'Mason Mount', + jersey: 7, + goals: 2, + speed: 6, + assits: 4, + 'passing accuracy': 8, + 'defensive involvements': 1, + }, +}; + +const readline = require('readline').createInterface({ + input: process.stdin, + output: process.stdout, +}); + +function Retry() { + readline.question( + '\nWhat do you want to do?\n1.- Return to main menu\n2.- Quit system\n', + n => { + if (n == 1) return menu(); + if (n == 2) { + console.log('Thank you see you!, next time'); + return readline.close(); + } + } + ); +} +function menu() { + readline.question( + '======WELCOME TO THE SYSTEM========\n Select an option\n1.- fastest player\n2.- top goal scorer\n3.- player with the most assists\n4.- player with the highest passing accuracy\n5.- player with the most defensive involvements\n6.- Info of player\n7.- Compare two players\n8.- Quit system\n', + n => { + if (n == 1) { + let top = 0; + let fastest = ''; + for (const player in players) { + if (players[player]['speed'] >= top) { + top = players[player]['speed']; + fastest = `the fastest player is ${players[player]['name']} wtih ${players[player]['speed']} points of speed`; + } + } + console.log(fastest); + return Retry(); + } + + if (n == 2) { + let top = 0; + let scorer = ''; + for (const player in players) { + if (players[player]['goals'] >= top) { + top = players[player]['goals']; + scorer = `the fastest player is ${players[player]['name']} wtih ${players[player]['goals']} goals`; + } + } + console.log(scorer); + return Retry(); + } + if (n == 3) { + let top = 0; + let assits = ''; + for (const player in players) { + if (players[player]['assits'] >= top) { + top = players[player]['assits']; + assits = `the fastest player is ${players[player]['name']} wtih ${players[player]['assits']} assits`; + } + } + console.log(assits); + return Retry(); + } + if (n == 4) { + let top = 0; + let passing = ''; + for (const player in players) { + if (players[player]['passing accuracy'] >= top) { + top = players[player]['passing accuracy']; + passing = `the fastest player is ${players[player]['name']} wtih ${players[player]['passing accuracy']} successfull passes`; + } + } + console.log(passing); + return Retry(); + } + if (n == 5) { + let top = 0; + let defensive = ''; + for (const player in players) { + if (players[player]['defensive involvements'] >= top) { + top = players[player]['defensive involvements']; + defensive = `the fastest player is ${players[player]['name']} wtih ${players[player]['defensive involvements']} defensive actions`; + } + } + console.log(defensive); + return Retry(); + } + if (n == 6) { + readline.question("\nSelect the Player's jersey number\n", n => { + console.log(players[n]); + return Retry(); + }); + } + if (n == 7) { + readline.question('\nenter 2 players numbers\n', a => { + readline.question('second number\n', b => { + console.log(players[a], '\n', players[b]); + return Retry(); + }); + }); + } + if (n == 8) { + console.log('Thank you!, see you next time.'); + return readline.close(); + } + } + ); +} +menu(); diff --git a/jmarquez/ejercicio02/index.js b/jmarquez/ejercicio02/index.js new file mode 100644 index 0000000..56a0e5e --- /dev/null +++ b/jmarquez/ejercicio02/index.js @@ -0,0 +1,68 @@ +// 2. A travel agency has a special offer for traveling in any season of 2024. Their destinations are: + +// Winter: Andorra and Switzerland. In Andorra, there are skiing activities, and in Switzerland, there's a tour of the Swiss Alps. +// Summer: Spain and Portugal. In Spain, there are hiking and extreme sports activities. In Portugal, there are activities on the beaches. +// Spring: France and Italy. In France, there are extreme sports activities, and in Italy, there's a cultural and historical tour. +// Autumn: Belgium and Austria. In Belgium, there are hiking and extreme sports activities, and in Austria, there are cultural and historical activities. +// Note: Traveling in winter costs $100, in autumn $200, in spring $300, and in summer $400. +// Design a system that helps users choose their best destination according to their personal preferences and the season they want to travel in. +// 12. Important: With the information you have, you should ask the user the right questions and display on screen what their best destination would be. + +// Clue: You could consider the user's budget + +const seasons = [ + { + winter: { + andorra: ['skiing activities'], + Switzerland: ['tour of the Swiss Alps'], + cost: 100, + }, + summer: { + spain: ['hiking', 'extreme sports'], + Portugal: ['beaches'], + cost: 400, + }, + spring: { + france: ['extreme sports'], + italy: ['cultural and historical tour'], + cost: 300, + }, + autumn: { + belgium: ['hiking', 'extreme sports'], + austria: ['cultural and historical activities'], + cost: 200, + }, + }, +]; +const readline = require('readline').createInterface({ + input: process.stdin, + output: process.stdout, +}); +function menu() { + readline.question( + 'Welcome to the traveling destination service\nPlease enter your activitty interest\n', + act => { + let j = 0; + let countries = ''; + let seasonList = ''; + + for (const i in seasons[0]) { + let interest = Object.values(seasons[0][i]); + let inter = Object.keys(seasons[0][i]); + if (interest[0].includes(act)) { + delete inter[2]; + inter.forEach(e => { + if (seasons[0][i][e].includes(act)) countries += e + ' '; + }); + seasonList += i + ' '; + } + j++; + } + console.log( + `Your activity ${act} is avaliable in the countries: ${countries} in the seasons: ${seasonList}` + ); + return readline.close(); + } + ); +} +menu(); diff --git a/jmarquez/ejercicio03/index.js b/jmarquez/ejercicio03/index.js new file mode 100644 index 0000000..1b0217b --- /dev/null +++ b/jmarquez/ejercicio03/index.js @@ -0,0 +1,147 @@ +// The Valencia Hospital is developing an application to manage appointments. Design an algorithm for this application with the following features: + +// It must have a login and validate the data; after the third failed attempt, it should be locked. +// The user can schedule an appointment for: General Medicine, Emergency Care, Clinical Analysis, Cardiology, Neurology, Nutrition, Physiotherapy, Traumatology, and Internal Medicine. +// There are 3 doctors for each specialty. +// The user can only book one appointment per specialist. An error message should be displayed if the user tries to choose two appointments with the same doctor or the same specialty. As a developer, you can choose the doctors' names. +// The maximum limit for appointments, in general, is 3. +// Upon selecting a specialty, it will display if the user prefers a morning or afternoon appointment and show available hours. As a developer, you can choose the hours. +// Display available specialists. +// The user can choose their preferred specialist. +// The basic process is: Login -> Choose specialty -> Choose doctor -> Choose time slot. +const readline = require('readline').createInterface({ + input: process.stdin, + output: process.stdout, +}); + +const users = [ + { + nam: 'jon', + pass: '123', + appointment: [], + }, + { + nam: 'Kate Wong', + pass: '@PASSujhp', + appointment: [], + }, +]; + +const specialities = [ + { + speciality_name: 'General Medicine', + doctors: ['manuel', 'jose', 'fernando'], + hours: ['10:am', '2:00pm'], + }, + { + speciality_name: 'Emergency Care', + doctors: ['charles xavier', 'walter white', 'zoiberg'], + hours: ['9:00am', '1:00pm'], + }, + { + speciality_name: 'Clinical Analysis', + doctors: ['alberto', 'roberto', 'filiberto'], + hours: ['8:00am', '3:00pm'], + }, + { + speciality_name: 'Cardiology', + doctors: ['maria', 'fernanda', 'rosio'], + hours: ['7:50am', '3:00pm'], + }, + { + speciality_name: 'Neurology', + doctors: ['daniel', 'devorah', 'isole'], + hours: ['8:50am', '4:00pm'], + }, + { + speciality_name: 'Nutrition', + doctors: ['francia', 'arturo', 'martina'], + hours: ['9:50am', '5:00pm'], + }, + { + speciality_name: 'Physiotherapy', + doctors: ['luna', 'isabel', 'valentina'], + hours: ['10:50am', '6:00pm'], + }, + { + speciality_name: 'Internal Medicine', + doctors: ['yesi', 'antonio', 'magdalena'], + hours: ['6:50am', '7:00pm'], + }, +]; + +let logTry = 3; +let maximumAppointment = 0; + +function login() { + readline.question('\n Insert you user: ', user => { + readline.question('\n Enter your password: ', pass => { + if (logTry === 1) { + console.log('\nSystem locked'); + return readline.close(); + } + const USER_AUTH = users.filter( + registeredUser => registeredUser.nam == user + ); + const PASS_AUTH = USER_AUTH.filter( + registeredUser => registeredUser.pass == pass + ); + + if (USER_AUTH.length == 0 || PASS_AUTH.length == 0) { + logTry--; + console.log(`User or password not found, tries remaining: ${logTry}`); + return login(); + } + delete USER_AUTH[0].pass; + menu(USER_AUTH[0]); + }); + }); +} + +function menu(userData) { + if (maximumAppointment >= 3) + return console.log( + `Maximun limit of appoinments (${maximumAppointment}) reached` + ); + readline.question('\nWelcome! Select the speciality please: ', str => { + chooseDoctor(specialities[str], userData); + }); + + specialities.forEach((index, value) => { + console.log(`\n${value}.- ${index.speciality_name} `); + }); +} + +function chooseDoctor(speciality, userData) { + readline.question( + `\nWelcome! Select the doctor for ${speciality.speciality_name} please: `, + str => { + const doctorName = speciality.doctors[str]; + delete speciality.doctors[str]; + if (userData.appointment.includes(doctorName)) { + console.log( + `You already are made appointment with the doctor ${doctorName}` + ); + chooseDoctor(speciality, userData); + } else { + userData.appointment.push(doctorName); + maximumAppointment++; + console.log('appointment successfully!'); + chooseHour(speciality); + } + } + ); + speciality.doctors.forEach((name, index) => { + console.log(`\n${index}.- ${name}`); + }); +} +function chooseHour(speciality) { + readline.question('\nChoose an avaliable hour:\n', hour => { + console.log(`Your appointment is set to ${speciality.hours[hour]}`); + return readline.close(); + }); + speciality.hours.forEach((name, index) => { + console.log(`\n${index}.- ${name}`); + }); +} +login(); diff --git a/jmarquez/ejercicio03/package.json b/jmarquez/ejercicio03/package.json new file mode 100644 index 0000000..45071d3 --- /dev/null +++ b/jmarquez/ejercicio03/package.json @@ -0,0 +1,16 @@ +{ + "name": "ejercicio03", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", + "start": "nodemon ./index.js" + }, + "keywords": [], + "author": "", + "license": "ISC", + "devDependencies": { + "nodemon": "^3.0.2" + } +} diff --git a/jmarquez/ejercicio04/index.js b/jmarquez/ejercicio04/index.js new file mode 100644 index 0000000..5553e0d --- /dev/null +++ b/jmarquez/ejercicio04/index.js @@ -0,0 +1,134 @@ +// 4. The RH Hotels chain has hired you to design the booking algorithm for their mobile application: + +// Login; it should be locked after the third failed attempt. +// The RH Hotels chain exists in 5 countries: Spain, France, Portugal, Italy, and Germany. +// Each country has its own hotels located in: Madrid, Barcelona, Valencia, Munich, Berlin, Rome, Milan, Paris, Marseille, Madeira, Lisbon, and Porto. +// All hotels have 24 rooms each: 6 VIP suites, 3 single rooms, 6 double rooms, 6 group rooms, and 3 luxury suites. +// The user can make reservations at any time of the year and at any hour, and book as many rooms as desired. +// Single rooms are priced at $100 per night, double rooms at $200 per night, group rooms at $350 per night, '' +// VIP suites at $450 per night, and luxury suites at $550 per night, applicable at any time of the year. +// The algorithm functions as follows: Login, choose country, choose city, choose room type, select the number of nights, +// collect user data (name, surname, ID/passport), +// print the total cost, and if the user agrees, print a confirmation message for the reservation. If not, return to the main menu. +const readline = require('readline').createInterface({ + input: process.stdin, + output: process.stdout, +}); + +const users = [ + { + nam: 'jon', + pass: '123', + appointment: [], + }, + { + nam: 'Kate Wong', + pass: '@PASSujhp', + appointment: [], + }, +]; +const countries = [ + { Spain: ['Madrid', 'Barcelona', 'Valencia'] }, + { France: ['Paris', 'Marseille'] }, + { Portugal: ['Lisbon', 'Porto'] }, + { Italy: ['Rome', 'Milan'] }, + { Germany: ['Munich', 'Berlin'] }, +]; +const rooms = [ + { 'VIP Suite': 450 }, + { 'Single rom': 100 }, + { 'Double rom': 200 }, + { 'Group rom': 350 }, + { 'Luxury suite': 550 }, +]; + +let selectedCountry = ''; +let selectedCity = ''; +let selectedRoom = {}; + +let logTry = 3; +function login() { + readline.question('\n Insert you user: ', user => { + readline.question('\n Enter your password: ', pass => { + if (logTry === 1) { + console.log('\nSystem locked'); + return readline.close(); + } + const USER_AUTH = users.filter( + registeredUser => registeredUser.nam == user + ); + const PASS_AUTH = USER_AUTH.filter( + registeredUser => registeredUser.pass == pass + ); + + if (USER_AUTH.length == 0 || PASS_AUTH.length == 0) { + logTry--; + console.log(`User or password not found, tries remaining: ${logTry}`); + return login(); + } + menu(); + }); + }); +} +function menu() { + readline.question( + '\nWELCOME TO RH HOTELS BOKKING SYSTEM\nSelect your country: ', + n => { + selectCity(n); + } + ); + countries.forEach((value, key) => { + console.log(`\n${key}.- ${Object.keys(value).toString()}`); + }); +} +function selectCity(country) { + const list = Object.values(countries[country]); + selectedCountry = Object.keys(countries[country]).toString(); + readline.question('\nSelect your city: ', n => { + selectedCity = list[0][n]; + selectRom(); + }); + list[0].forEach((value, key) => { + console.log(`\n${key}.- ${value}`); + }); +} +function selectRom() { + readline.question('\nSelect the room type: ', n => { + selectedRoom = rooms[n]; + numberNIghtsd(); + }); + rooms.forEach((value, index) => { + console.log(`\n${index}.- ${Object.keys(value)}: $${Object.values(value)}`); + }); +} +function numberNIghtsd() { + readline.question('\nSelect the amounts of nights to reserve: ', n => { + finishProcess(n); + }); +} +function finishProcess(n) { + readline.question('\nPlease enter your name: ', name => { + readline.question('\nPlease enter your surname: ', surname => { + readline.question('\nPleasee enter your ID/Passport: ', passport => { + const initialCost = Number(Object.values(selectedRoom)); + console.log(`\nToal to pay is: $${initialCost * n}`); + readline.question(`\nAre you agree? ("yes/no"): `, res => { + if (res !== 'yes') { + return menu(); + } else { + console.log(` + Congratulations!, the reservatios is done for + Name: ${name} ${surname} + ID/Passport: ${passport} + Destinatation: ${selectedCountry} - ${selectedCity} + Romm type:${Object.keys(selectedRoom).toString()} + Total to pay: $${initialCost * n} + `); + return readline.close(); + } + }); + }); + }); + }); +} +login(); diff --git a/jmarquez/ejercicio04/package.json b/jmarquez/ejercicio04/package.json new file mode 100644 index 0000000..5cfc310 --- /dev/null +++ b/jmarquez/ejercicio04/package.json @@ -0,0 +1,5 @@ +{ + "devDependencies": { + "nodemon": "^3.0.2" + } +} diff --git a/jmarquez/ejercicio05/index.js b/jmarquez/ejercicio05/index.js new file mode 100644 index 0000000..69f65ea --- /dev/null +++ b/jmarquez/ejercicio05/index.js @@ -0,0 +1,148 @@ +// 5. Turkish Airlines has just launched an offer to travel among the following destinations: Turkey, Greece, Lebanon, Spain, and Portugal. Develop an algorithm with the following characteristics: +// It must have a login and validate the data; after the third failed attempt, it should be locked. +// The user must choose the origin country and the destination country, the flight date, and the condition: Economy or First Class. +// The user must choose if they want to check an additional piece of luggage into the hold. +// Hand luggage is free of charge. +// The user must purchase both the outbound and return tickets. +// The user can choose their preferred meal: Regular, Vegetarian, Kosher. +// The program must collect the following data: Name, country of origin, passport, and destination country. +// Upon completing the process, the system will display everything the user has previously chosen along with their information. +// The system will provide the option to confirm the reservation or cancel it. If the user chooses YES, a confirmation message will appear. If not, it will return to the main menu. +const readline = require('readline').createInterface({ + input: process.stdin, + output: process.stdout, +}); +const users = [ + { + nam: 'jon', + pass: '123', + }, + { + nam: 'Kate Wong', + pass: '@PASSujhp', + }, +]; +const countries = ['Turkey', 'Greece', 'Lebanon', 'Spain', 'Portugal']; +const condition = ['Economy', 'First Class']; +const meal = ['Regular', 'Vegetarian', 'Kosher']; +let userName = ''; +let origin = ''; +let destinatation = ''; +let departureDate = ''; +let returnDate = ''; +let passport = ''; +let luggage = false; +let category = ''; +let mealType = ''; + +let logTry = 3; +function login() { + readline.question('\n Insert you user: ', user => { + readline.question('\n Enter your password: ', pass => { + if (logTry === 1) { + console.log('\nSystem locked'); + return readline.close(); + } + const USER_AUTH = users.filter( + registeredUser => registeredUser.nam == user + ); + const PASS_AUTH = USER_AUTH.filter( + registeredUser => registeredUser.pass == pass + ); + + if (USER_AUTH.length == 0 || PASS_AUTH.length == 0) { + logTry--; + console.log(`User or password not found, tries remaining: ${logTry}`); + return login(); + } + menu(); + }); + }); +} +function menu() { + readline.question( + '\nWelcome to Turkish Airlines System\nEnter your name please: ', + str => { + userName = str; + readline.question('\nEnter your passport ID: ', pass => { + passport = pass; + originCountry(); + }); + } + ); +} +function originCountry() { + readline.question('\nSelect the country of origin: ', str => { + origin = countries[str]; + readline.question( + '\nEnter the outbound date (format: DD-MM-YY): ', + date => { + departureDate = date; + destinatationCountry(); + } + ); + }); + countries.forEach((value, key) => { + console.log(`\n${key}.- ${value}`); + }); +} +function destinatationCountry() { + readline.question('\nSelect destinatation country: ', str => { + destinatation = countries[str]; + readline.question('\nEnter the return date (format: DD-MM-YY): ', date => { + returnDate = date; + extraLuggage(); + }); + }); + countries.forEach((value, key) => { + console.log(`\n${key}.- ${value}`); + }); +} +function extraLuggage() { + readline.question('Do you want add extra luggage? (yes/no): ', answer => { + if (answer == 'yes') luggage = true; + selectCategory(); + }); +} +function selectCategory() { + readline.question('\nSelect category: ', c => { + category = condition[c]; + selectMeal(); + }); + condition.forEach((value, key) => { + console.log(`\n${key}.- ${value}`); + }); +} +function selectMeal() { + readline.question('\nSelect type of meal: ', m => { + mealType = meal[m]; + reservation(); + }); + meal.forEach((value, key) => { + console.log(`\n${key}.- ${value}`); + }); +} + +function reservation() { + console.log(` + Reservation details: + Name: ${userName} + Category: ${category} + Type of meal: ${mealType} + Passport ID: ${passport} + Country of origin: ${origin} + Date of departure: ${departureDate} + Country of destination: ${destinatation} + Date of return: ${returnDate} + Extra luggage: ${luggage} + `); + readline.question('\nPlease confirm the oerder (yes/no): ', conf => { + if (conf == 'yes') { + console.log('\nReservatioon made succesfully!'); + return readline.close(); + } else { + menu(); + } + }); +} +login(); diff --git a/jmarquez/ejercicio05/package.json b/jmarquez/ejercicio05/package.json new file mode 100644 index 0000000..810659f --- /dev/null +++ b/jmarquez/ejercicio05/package.json @@ -0,0 +1,13 @@ +{ + "name": "ejercicio05", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", + "start": "node --watch index.js" + }, + "keywords": [], + "author": "", + "license": "ISC" +}