Training Days block scope still acting like it's global

I have followed the code step by step and copied the video on how to get the random number to behave within a block so random values are generated sequentially. I cannot see where this has gone wrong as it is pretty much verbatim to the instructions.

Please let me know if this is a bug or what my error is:

// The scope of random is too loose

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’;

// The scope of days is too tight
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 name = ‘Nala’;
// The scope of name is too tight
const logEvent = (name, event) => {

console.log(${name}'s event is: ${event});

const logTime = (name, event) => {
console.log(${name}'s time to train is: ${days} days);

const event = getRandEvent();
const days = getTrainingDays(event);
// Define a name variable. Use it as an argument after updating logEvent and logTime

logEvent(name, event);
logTime(name, days);

const event2 = getRandEvent();
const days2 = getTrainingDays(event2);
const name2 = ‘Warren’;

logEvent(name2, event2);
logTime(name2, days2);

What do you mean by “random values generated sequentially”?

The code you have posted already generates 2 [possibly] different random values; one for Nala, and one for Warren.


Thanks, I fixed it in the end but it was doing some weird stuff. It initially wasn’t giving me different events despite the random generator being in block scope. It is all sorted now though.