[英]Why exercism.org doesn't accept my solution JS?
I just started with exercism and doing Javascript exercise 2, Lucian's Luscious Lasagna.我刚开始练习并做 Javascript 练习 2, Lucian 的 Luscious Lasagna。
I wrote all the code on my VSCode and it all worked fine.我在我的 VSCode 上编写了所有代码,一切正常。 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.它还显示了一些我没见过的东西,比如在函数内部的“const”和“throw new Error”之前的“export”。 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));
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.您的答案是正确的,但是当您在 vs 代码中编写它并在练习中进行测试时,它不会起作用,因为您没有导出任何东西。 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));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.