Skip to content

Instantly share code, notes, and snippets.

@codecademydev

codecademydev/trainingDays.js Secret

Created Feb 20, 2021
Embed
What would you like to do?
Codecademy export
const name = 'Nala';
const name2 = 'Warren';
const getRandEvent = () => {
const random = Math.floor(Math.random() * 3);
if (random === 0) {
return 'Marathon';
} else if (random === 1) {
return 'Triathlon';
} else if (random === 2) {
return 'Pentathlon';
}
};
const getTrainingDays = event => {
let days;
if (event === 'Marathon') {
days = 50;
} else if (event === 'Triathlon') {
days = 100;
} else if (event === 'Pentathlon') {
days = 200;
}
return days;
};
const logEvent = (name, event) => {
console.log(`${name}'s event is: ${event}`);
};
const logTime = (name, days) => {
console.log(`${name}'s time to train is: ${days} days`);
};
const event = getRandEvent();
const days = getTrainingDays(event);
logEvent(name, event);
logTime(name, days);
console.log();
const event2 = getRandEvent();
const days2 = getTrainingDays(event2);
logEvent(name2, event2);
logTime(name2, days2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment