Why exercism.org doesn't accept my solution JS?

I just started with exercism and doing Javascript exercise 2, Lucian's Luscious Lasagna.

I wrote all the code on my VSCode and it all worked fine. but when I insert it in the editor on exercise, it shows errors and doesn't accept it. It is also showing some things I haven't seen like 'export' before 'const' and 'throw new Error' inside the function. I'm really not sure how this works. How can I do it in a way that exercism editor would accept?

const PREPARATION_MINUTES_PER_LAYER = 2;
const EXPECTED_MINUTES_IN_OVEN = 40;
function remainingMinutesInOven(actualMinutesInOven) { return EXPECTED_MINUTES_IN_OVEN - actualMinutesInOven;
}
console.log(remainingMinutesInOven(30));
function preparationTimeInMinutes(numberOfLayers) { return numberOfLayers * 2;
}
console.log(preparationTimeInMinutes(2));
function totalTimeInMinutes(numberOfLayers, actualMinutesInOven) { return numberOfLayers * 2 + actualMinutesInOven;
}
console.log(totalTimeInMinutes(3, 20));

1 Answer

Your answer is correct, but as you wrote it in vs code and testing in exercism, it is not going to work, because you haven't exported anything. To test, you have to export your variables and function

This should work:

export const PREPARATION_MINUTES_PER_LAYER = 2;
export const EXPECTED_MINUTES_IN_OVEN = 40;
export function remainingMinutesInOven(actualMinutesInOven) { return EXPECTED_MINUTES_IN_OVEN - actualMinutesInOven;
}
console.log(remainingMinutesInOven(30));
export function preparationTimeInMinutes(numberOfLayers) { return numberOfLayers * 2;
}
console.log(preparationTimeInMinutes(2));
export function totalTimeInMinutes(numberOfLayers, actualMinutesInOven) { return numberOfLayers * 2 + actualMinutesInOven;
}
console.log(totalTimeInMinutes(3, 20));
0

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like