Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
191 changes: 191 additions & 0 deletions Reto_1/coachManager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
// 1. Manchester United FC has hired you as a developer. Develop a program that helps the coach identify their fastest player, player with the most goals, assists, passing accuracy, and defensive involvements.
// The system should also allow comparison between two players. Use the following player profiles:

// Bruno Fernandes: 5 goals, 6 points in speed, 9 points in assists, 10 points in passing accuracy, 3 defensive involvements. Corresponds to jersey number 8.
// Rasmus Hojlund: 12 goals, 8 points in speed, 2 points in assists, 6 points in passing accuracy, 2 defensive involvements. Corresponds to jersey number 11.
// Harry Maguire: 1 goal, 5 points in speed, 1 point in assists, 7 points in passing accuracy, 9 defensive involvements. Corresponds to jersey number 5.
// Alejandro Garnacho: 8 goals, 7 points in speed, 8 points in assists, 6 points in passing accuracy, 0 defensive involvements. Corresponds to jersey number 17.
// Mason Mount: 2 goals, 6 points in speed, 4 points in assists, 8 points in passing accuracy, 1 defensive involvement. Corresponds to jersey number 7.
// The program functions as follows: The coach accesses the system and encounters a menu with the following options:

// Player Review: By entering the player's jersey number, they can access the player's characteristics.
// Compare two players: The system prompts for two jersey numbers and displays the data of both players on screen.
// Identify the fastest player: Displays the player with the most points in speed.
// Identify the top goal scorer: Displays the player with the most points in goals.
// Identify the player with the most assists: Displays the player with the most points in assists.
// Identify the player with the highest passing accuracy: Displays the player with the most points in passing accuracy.
// Identify the player with the most defensive involvements: Displays the player with the most points in defensive involvements.
// The system should also allow returning to the main menu.
import * as readline from "node:readline/promises";
import { stdin as input, stdout as output } from "node:process";
import { log } from "node:console";
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
const players = [
{
name: "Bruno Fernandes",
goals: 5,
speed: 6,
assists: 9,
passingAccuracy: 10,
defensiveInvolvements: 3,
jerseyNumber: 8,
},
{
name: "Rasmus Hojlund",
goals: 12,
speed: 8,
assists: 2,
passingAccuracy: 6,
defensiveInvolvements: 2,
jerseyNumber: 11,
},
{
name: "Harry Maguire",
goals: 1,
speed: 5,
assists: 1,
passingAccuracy: 7,
defensiveInvolvements: 9,
jerseyNumber: 5,
},
{
name: "Alejandro Garnacho",
goals: 8,
speed: 7,
assists: 8,
passingAccuracy: 6,
defensiveInvolvements: 0,
jerseyNumber: 17,
},
{
name: "Mason Mount",
goals: 2,
speed: 6,
assists: 4,
passingAccuracy: 8,
defensiveInvolvements: 1,
jerseyNumber: 7,
},
];
async function askToContinue() {
const answer = await rl.question(
"Do you want to continue in the program? (y/n): "
);
if (answer.toLowerCase() !== "y") {
isProgramRunning = false;
}
}

async function playerReview() {
const jerseyNumber = await rl.question(
"Input the jersey number of the player: "
);
const player = players.find((player) => player.jerseyNumber == jerseyNumber);
if (player) {
console.log("Statistics");
console.log(`
Name: ${player.name}
Number of goals: ${player.goals}
Points in speed: ${player.speed}
Points in assists: ${player.assists}
Points in passing accuracy: ${player.passingAccuracy}
Defensive involvements: ${player.defensiveInvolvements}
`);
} else {
console.log("Player no found");
}
}
async function playersCompare() {
await playerReview();
await playerReview();
}
async function selectBestPlayer(statistic) {
let bestPlayer = null
players.forEach((player) => {
if (statistic in player) {
if (bestPlayer === null ||bestPlayer[statistic] < player[statistic]) {
bestPlayer = player
}
}
});
return bestPlayer;
}
let isProgramRunning = true;
while (isProgramRunning) {
console.log("Welcome to the Player Review of Manchester United FC!");
console.log("1. Player Review:");
console.log("2. Compare two players:");
console.log("3. Identify the fastest player");
console.log("4. Identify the top goal scorer");
console.log("5. Identify the player with the most assists");
console.log("6. Identify the player with the highest passing accuracy");
console.log("7. Identify the player with the most defensive involvements");
console.log("8. Exit");
let optionMenu = await rl.question(
"select the option according to the number in the menu: "
);
switch (Number(optionMenu)) {
case 1:
await playerReview();
await askToContinue();
break;
case 2:
await playersCompare();
await askToContinue();
break;
case 3:
const fastestPlayer = await selectBestPlayer("speed");
console.log(
`Fastest player: ${fastestPlayer.name} with a speed score of ${fastestPlayer.speed}`
);
await askToContinue();

break;
case 4:
const topGoalScorer = await selectBestPlayer("goals");
console.log(
`Top goal scorer: ${topGoalScorer.name} with ${topGoalScorer.goals} goals`
);
await askToContinue();

break;
case 5:
const mostAssistsPlayer = await selectBestPlayer("assists");
console.log(
`Player with most assists: ${mostAssistsPlayer.name} with ${mostAssistsPlayer.assists} assists`
);
await askToContinue();
break;
case 6:
const highestPassingAccuracyPlayer = await selectBestPlayer(
"passingAccuracy"
);
console.log(
`Player with highest passing accuracy: ${highestPassingAccuracyPlayer.name} with ${highestPassingAccuracyPlayer.passingAccuracy}% passing accuracy`
);
await askToContinue();
break;
case 7:
const mostDefensivePlayer = await selectBestPlayer(
"defensiveInvolvements"
);
console.log(
`Player with most defensive involvements: ${mostDefensivePlayer.name} with ${mostDefensivePlayer.defensiveInvolvements} defensive involvements`
);
await askToContinue();
break;
case 8:
isProgramRunning = false;
break;

default:
console.log(`
Please enter a valid option.
`);
break;
}
}
rl.close();
104 changes: 104 additions & 0 deletions Reto_2/travelAgency.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// 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
import inquirer from "inquirer";
const travelsInfo = [
{
season: "winter",
price: 100,
countries: {
Andorra: ["skiing activities"],
Switzerland: ["tour of the Swiss Alps"],
},
},
{
season: "summer",
price: 400,
countries: {
Spain: ["hiking", "extreme sports activities"],
Portugal: ["activities on the beaches"],
},
},
{
season: "spring",
price: 300,
countries: {
France: ["extreme sports activities"],
Italy: ["cultural and historical tour"],
},
},
{
season: "autumn",
price: 200,
countries: {
Belgium: ["hiking", "extreme sports activities"],
Austria: ["cultural and historical activities"],
},
},
];

const budgetQuestion = {
type: "input",
name: "budget",
message: "enter your budget:",
validate:(input)=>{
const inputNumber=Number(input)
const minAmount=100
if (isNaN(inputNumber)) {
return "Enter a number value";
}else if((inputNumber)< 100){
return `The minimum price of the trips is $${minAmount}`
}else{
return true
}}
};
console.log("Welcome to the Travel Destination Selector!");
console.log("Answer a few questions to find your best travel destination.\n");
const { budget } = await inquirer.prompt(budgetQuestion);

const seasonAvailable = travelsInfo.filter((travel) => travel.price <= Number(budget)).map((travel) => travel.season);
const seasonQuestion = {

type: "list",
name: "season",
message: "What season would you like to travel?",
choices:seasonAvailable
};
let season
if (seasonAvailable.length>1) {
const answerseason = await inquirer.prompt(seasonQuestion);
season=answerseason.season
}else{
console.log(`Due to the available budget, the system has automatically chosen the season: ${seasonAvailable[0]}`)
season=seasonAvailable[0]
}
const selectedTravel = travelsInfo.find((travel)=> travel.season===season)
const ActtitiesAvailables = Object.values(selectedTravel.countries).flatMap(activities => activities);
const activitiesQuestion = {

type: "list",
name: "activity",
message: "What activities do you want to do?",
choices:ActtitiesAvailables
}
let selectedCountry=null
const {activity} = await inquirer.prompt(activitiesQuestion);
for (const country in selectedTravel.countries) {
if (selectedTravel.countries[country].includes(activity)) {
selectedCountry = country;
}
}
console.log(`Based on your preferences, your best destination is:`);
console.log(`Country: ${selectedCountry}`);
console.log(`Activities: ${selectedTravel.countries[selectedCountry]}`);
console.log(`Season: ${season}`);
console.log(`Price: $${selectedTravel.price}`);
Loading