简体   繁体   English

为什么 exercism.org 不接受我的解决方案 JS?

[英]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.

相关问题 为什么我的 setState 不接受这个 object? - Why my setState doesn't accept this object? Javascript运动解决方案。 为什么一个比另一个更好? - Javascript exercism solution. Why is one better than the other? 为什么我的文本框不接受小数点? - Why doesn't my textbox accept decimal point? 为什么我的Raspberry数字标牌解决方案无法正常工作? - Why my digital signage solution with Raspberry doesn't correctly works? 带有Vue.js的ASP.NET Core不接受我的纯js组件 - ASP.NET Core with Vue.js doesn't accept my pure js component 将.net MVC视图中的布尔值传递给javascript,但JS不接受True,想要为true - Passing a boolean value in my .net MVC view to a javascript, but JS doesn't accept True, wants true 为什么我的JS函数不能与按钮一起使用? - Why doesn't my JS function work with my button? 为什么在我的 JS 弹出窗口中,我的 html 表单不起作用? - Why in my JS popup my html form doesn't work? 为什么我的 web 应用程序(ReactJS)不接受后端发送的 cookies? - Why my web application (ReactJS) doesn't accept the cookies sent by backend? `?` 在某些对象属性之前是什么意思? 为什么我的 ts 文件不接受它? - what `?` means before some object attribute? and why my ts file doesn´t accept it?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM